Hallo
Bijgevoegd zijn twee codes die hetzelfde doen, hun verschil ligt in het respecteren van bepaalde programmeerbeperkingen die soms worden opgelegd (geen "on error goto renvoi_ligne_de_traitement)
in 3D en 2D moeten de parameters exact dezelfde naam hebben, wat op dit moment niet het geval is "RAL" in 3D en "RAL CODE" in 2D
De codes zijn niet geoptimaliseerd, voordat u de macro start, moet u ervoor zorgen dat er een weergave van de 3d in uw catdrawing is en om te voorkomen dat u deze overal start, voegt u een test toe aan het begin van de code om te controleren of u de macro start vanuit een catdrawing en dat er een weergave bestaat.
Sub PremiereVue()
Dim Err As Boolean
Err = False
'''''''''''''''''''''''''''''''''''''
' Récupération du nom du fichier 3D '
'''''''''''''''''''''''''''''''''''''
Set ParentVue = CATIA.ActiveDocument.Sheets.ActiveSheet.Views.Item(3).GenerativeLinks.FirstLink
Do
Set ParentVue = ParentVue.Parent
Loop Until ParentVue.Parent.Name = "CNEXT"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''
' Récuperations des paramètres '
''''''''''''''''''''''''''''''''
For Each para In Array("MATIERE", "TRAITEMENT", "REVETEMENT", "TOLERANCES", "RUGOSITE", "RAL", "REFERENCE", "PROJET", "MASSE", "DENOMINATION", "CLIENT")
Err = False
On Error GoTo ErrParam3D
TestErr = ParentVue.Product.Parameters.Item(para).Value
On Error GoTo ErrParam2D
TestErr = CATIA.ActiveDocument.Parameters.Item(para).Value
If Err = False Then
'MsgBox para & Chr(10) & ParentVue.Product.Parameters.Item(para).Value & Chr(10) & CATIA.ActiveDocument.Parameters.Item(para).Value
CATIA.ActiveDocument.Parameters.Item(para).Value = ParentVue.Product.Parameters.Item(para).Value
End If
Next
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Exit Sub
ErrParam3D:
MsgBox para & " n'existe pas dans le 3D"
Err = True
Resume Next
ErrParam2D:
MsgBox para & " n'existe pas dans le 2D"
Err = True
Resume Next
End Sub
Andere versie
Sub PremiereVue_V1()
Dim Existe3D As Boolean
Dim Existe2D As Boolean
Dim Para3D()
Dim Para2D()
'''''''''''''''''''''''''''''''''''''
' Récupération du nom du fichier 3D '
'''''''''''''''''''''''''''''''''''''
Set ParentVue = CATIA.ActiveDocument.Sheets.ActiveSheet.Views.Item(3).GenerativeLinks.FirstLink
Do
Set ParentVue = ParentVue.Parent
Loop Until ParentVue.Parent.Name = "CNEXT"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''
' Récuperations des paramètres du 3D '
''''''''''''''''''''''''''''''''''''''
ReDim Para3D(1 To 2, 1 To ParentVue.Product.Parameters.Count)
For i = 1 To UBound(Para3D, 2)
Para3D(1, i) = ParentVue.Product.Parameters.Item(i).Name
On Error Resume Next
Para3D(2, i) = ParentVue.Product.Parameters.Item(i).Value
On Error GoTo 0
Next
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''
' Récuperations des paramètres du 2D '
''''''''''''''''''''''''''''''''''''''
ReDim Para2D(1 To 2, 1 To CATIA.ActiveDocument.Parameters.Count)
For i = 1 To UBound(Para2D, 2)
Para2D(1, i) = CATIA.ActiveDocument.Parameters.Item(i).Name
On Error Resume Next
Para2D(2, i) = CATIA.ActiveDocument.Parameters.Item(i).Value
On Error GoTo 0
Next
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
For Each para In Array("MATIERE", "TRAITEMENT", "REVETEMENT", "TOLERANCES", "RUGOSITE", "RAL", "REFERENCE", "PROJET", "MASSE", "DENOMINATION", "CLIENT")
For i = 1 To UBound(Para3D, 2)
If Para3D(1, i) = para Then
Existe3D = True
Exit For
Else
Existe3D = False
End If
Next
For j = 1 To UBound(Para2D, 2)
If Para2D(1, j) = para Then
Existe2D = True
Exit For
Else
Existe2D = False
End If
Next
If Existe3D = False Then
MsgBox para & " n'existe pas dans le 3D"
End If
If Existe2D = False Then
MsgBox para & " n'existe pas dans le 2D"
End If
If Existe3D = True And Existe2D = True Then
'MsgBox para & Chr(10) & Para3D(2, i) & Chr(10) & Para2D(2, j)
CATIA.ActiveDocument.Parameters.Item(para).Value = Para3D(2, i)
End If
Next
End Sub
Vriendelijke groeten