Bonjour,
Ci joints deux codes qui font la même chose, leurs différence réside dans le respect de certaines contraintes de programmation imposées quelquefois (pas de "on error goto renvoi_ligne_de_traitement)
il faut que dans le 3D et le 2D, les paramètres aient exactement le même nom, ce qui n'est pas le cas pour l'instant "RAL" dans le 3D et "CODE RAL" dans le 2D
Les codes ne sont pas optimisés, il faut avant de lancer la macro qu'il y ait une vue du 3d dans ton catdrawing et pour eviter de le lancer de n'importe où, ajouter en début de code un test pour vérifier que tu lances bien la macro depuis un catdrawing et qu'une vue existe.
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
autre 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
Cordialement