Witam
W załączeniu znajdują się dwa kody, które robią to samo, różnica polega na tym, że czasami nakładane są pewne ograniczenia programistyczne (nie ma "w przypadku błędu" przejdź do renvoi_ligne_de_traitement)
w 3D i 2D parametry muszą mieć dokładnie taką samą nazwę, co nie ma miejsca w tej chwili "RAL" w 3D i "RAL CODE" w 2D
Kody nie są optymalizowane, przed uruchomieniem makra potrzebujesz, aby w twoim rysunku kota był widok 3d i aby uniknąć uruchamiania go z dowolnego miejsca, dodaj test na początku kodu, aby sprawdzić, czy uruchamiasz makro z rysunku kota i czy istnieje widok.
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
Inna wersja
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
Pozdrowienia