Message 1 of 4
partDocument.Save trigger OnSaveDocument event
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have addin to change part file BOM Structure to Reference when a new file is saved with "Master" in the name.
It worked since IV 2012 to IV2020.
After upgrade to 2023.2 it cause IV to crash.
I traced to problem to PartDocument.Save().
It trigger OnSave event and cause an endless loop.
If I can get the new filename Before save, I can avoid the Save again.
Or anyway to avoid event trigger?
Private Sub M_ApplicationEvents_OnSaveDocument(
oDoc As _Document, BeforeOrAfter As EventTimingEnum, Context As NameValueMap,
ByRef HandlingCode As HandlingCodeEnum) Handles M_ApplicationEvents.OnSaveDocument
Dim oPartDoc As PartDocument
'Cannot get new filename Before
If BeforeOrAfter = EventTimingEnum.kAfter Then
'Check if new file, kAfter FileSaveCounter = 1
If oDoc.FileSaveCounter = 1 Then
If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
If (InStr(oDoc.DisplayName, "Master", CompareMethod.Text)) > 0 Then
oPartDoc = oDoc
oPartDoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
Saved = True
'IV2023 trigger OnSave event
oPartDoc.Save()
End If
End If
End If
End Sub