Hello
Trying desesperatly to CREATE A publication in MAcro Language VBA with the following code
Could someone help me please
Sub CATMain()
Dim EngCntEditor As Object: Set EngCntEditor = CATIA.ActiveEditor
' 1. Accès au service de publication (plus puissant que l'accès par l'objet)
Dim simPubService As Object
On Error Resume Next
Set simPubService = EngCntEditor.GetService("SimPublicationServices")
On Error GoTo 0
If simPubService Is Nothing Then
MsgBox "Le service de publication est indisponible. Vérifiez vos licences."
Exit Sub
End If
' 2. Récupérer l'assemblage racine
Dim myProdService As PLMProductService: Set myProdService = EngCntEditor.GetService("PLMProductService")
Dim myRootOcc As VPMRootOccurrence: Set myRootOcc = myProdService.RootOccurrence
Dim myRootRef As VPMReference: Set myRootRef = myRootOcc.ReferenceRootOccurrenceOf
Dim ioCATIA As Application
Set ioCATIA = CATIA
'Get The Active Object i.e. Root object
Dim ioVPMRootOccurence As VPMRootOccurrence
Set ioVPMRootOccurence = ioCATIA.ActiveEditor.ActiveObject
' Get the Child Occurences i.e. the objects below the root
Dim ioVPMOccurences As VPMOccurrences
Set ioVPMOccurences = ioVPMRootOccurence.Occurrences
' Get the first Child Occurence
Dim ioOccurence As VPMOccurrence
Set ioOccurence = ioVPMOccurences.Item(1)
' Get the VPM Instance from the Child Occurence
Dim ioVPMInstance As VPMInstance
Set ioVPMInstance = ioOccurence.InstanceOccurrenceOf
' Get the VPM Reference from the VPM Instance
Dim ioVPMReference As VPMReference
Set ioVPMReference = ioVPMInstance.ReferenceInstanceOf
' Get the VPM Representation Instances
Dim ioVPMRepInstances As VPMRepInstances
Set ioVPMRepInstances = ioVPMReference.repInstances
' A 3D Part may have multiple reps below it i.e. a Shape and a Drawing
' Get the first Representation Instance from the VPM Representation Instances
Dim ioVPMRepInstance As VPMRepInstance
Set ioVPMRepInstance = ioVPMRepInstances.Item(1)
' Get the VPM Representation Reference from the Representation Instance
Dim ioVPMRepReference As VPMRepReference
Set ioVPMRepReference = ioVPMRepInstance.ReferenceInstanceOf
' Get the Part from the VPM Representation Reference
Dim ioPart As Part
Set ioPart = ioVPMRepReference.GetItem("Part")
MsgBox ioPart.axisSystems.Item(2).name
' ' 3. Récupérer l'élément sélectionné
' Dim mySelection As Object: Set mySelection = EngCntEditor.Selection
' If mySelection.Count = 0 Then
' MsgBox "Sélectionnez l'axe 'RepTgt' dans l'arbre."
' Exit Sub
' End If
'mySelection.VisProperties.SetRealColor 255, 255, 0, 1 ' Repère en jaune
' 4. RÉCUPÉRATION DU LIEN CONTEXTUEL
Dim oAxis As Object: Set oAxis = ioPart.axisSystems.Item(2)
' On tente de créer une référence contextuelle
Dim myRef As Object
On Error Resume Next
' Set myRef = ioOccurence.CreateReferenceFromObject(oAxis) ' CREATE AN EMPTY PUBLICATION
Set myRef = ioPart.axisSystems.Item(1) 'DOESN'T CREATE ANY PUBLICATION
On Error GoTo 0
' 5. CRÉATION PAR LE SERVICE (Sans passer par la collection)
Dim pubName As String: pubName = "PubliRep"
Dim newPublication As Object
On Error Resume Next
' C'est la fonction la plus robuste de l'API 3DEXPERIENCE
Set newPublication = simPubService.CreatePublication(myRootRef, myRef, pubName)
On Error GoTo 0
' 6. VERIFICATION
If Not newPublication Is Nothing Then
MsgBox "SUCCÈS ! Publication créée via SimPublicationServices."
' Rafraîchissement forcé
Else
MsgBox "Même le service de simulation a échoué." & vbCrLf & _
"Vérifiez si l'objet racine (" & myRootRef.GetIdentifier & ") n'est pas verrouillé par un autre utilisateur."
End If
MsgBox newPublication.name
End Sub