Hello
Attached are two codes that do the same thing, their difference lies in the respect of certain programming constraints sometimes imposed (no "on error goto renvoi_ligne_de_traitement)
in 3D and 2D, the parameters must have exactly the same name, which is not the case for the moment "RAL" in 3D and "RAL CODE" in 2D
The codes are not optimized, before launching the macro you need that there is a view of the 3d in your catdrawing and to avoid launching it from anywhere, add a test at the beginning of the code to check that you are launching the macro from a catdrawing and that a view exists.
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
Other version
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
Kind regards