Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations SSS148 on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

trigger catia

Apr 22, 2025
1
Hello,

I’m trying to achieve the following in CATIA:
  • When the user clicks Save on the active document in CATIA, a message box should appear.
  • At the same time, a macro should run automatically and display the results.
Alternatively, if the user clicks a custom button in the UI for the active document, and then later clicks Save, it should still trigger the message box.
Here's the code I’ve tried so far:

Public WithEvents partDoc As PartDocument
Public WithEvents prodDoc As ProductDocument
Public WithEvents drawDoc As DrawingDocument

Public Sub Init(doc As Document)
' Check the document type and set the appropriate object for events
Dim docTypeName As String
docTypeName = LCase(TypeName(doc))

Select Case docTypeName
Case "partdocument"
Set partDoc = doc
Case "productdocument"
Set prodDoc = doc
Case "drawingdocument"
Set drawDoc = doc
Case Else
MsgBox "Unsupported document type: " & docTypeName, vbCritical
Exit Sub
End Select

MsgBox "Save event agent enabled for: " & docTypeName
End Sub

Private Sub partDoc_OnBeforeSave()
MsgBox "Saving Part... Agent triggered!"
End Sub

Private Sub prodDoc_OnBeforeSave()
MsgBox "Saving Product... Agent triggered!"
End Sub

Private Sub drawDoc_OnBeforeSave()
MsgBox "Saving Drawing... Agent triggered!"
End Sub


regards
Gokul
 

Part and Inventory Search

Sponsor