08-05-2016
08:34 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
08-05-2016
08:34 AM
VB.net error on ported VBA code
I have a VBA script that would save and replace all occurrences of a selected component. I've since ported that to my VB.net addin and now I'm having issues. When I use the script from my VB.net addin I get an illegal error when the script replaces parts with ilogic triggers in them. The exact same VBA does not cause this error. The error does not cause the operation to fail but it causes extra clicks and would probably scare the average person.
Is there a different way to find and replace that might not cause this or a way to prevent ilogic triggers from running when replacing components.
Error Message:
"Illegal attempt to create identified child transaction inside an unidentified transaction"
Imports Inventor
Module Save_Replace_All
Public Sub SaveReplaceAll()
'Checks if open document is assembly
If (ThisApplication.ActiveDocument.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject) Then
MsgBox("This is NOT an assembly document!", vbExclamation)
Exit Sub
End If
Dim oPart As ComponentOccurrence
Dim oPartDoc As Document
Dim NewFilePath As String
oPart = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select the part to save and replace all.")
If (oPart Is Nothing) Then Exit Sub
oPartDoc = oPart.Definition.Document
Dim oFileDlg As Inventor.FileDialog = Nothing
Call ThisApplication.CreateFileDialog(oFileDlg)
'check file type and set dialog filter
If oPartDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
oFileDlg.Filter = "Autodesk Inventor Part Files (*.ipt)|*.ipt"
ElseIf oPartDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
oFileDlg.Filter = "Autodesk Inventor Assembly Files (*.iam)|*.iam"
End If
oFileDlg.InitialDirectory = ThisApplication.FileLocations.Workspace
oFileDlg.FileName = Filename(oPartDoc.FullFileName)
oFileDlg.CancelError = True
Call oFileDlg.ShowSave()
If oFileDlg.FileName <> "" Then
NewFilePath = oFileDlg.FileName
Else
Exit Sub
End If
ThisApplication.SilentOperation = True
Call oPartDoc.SaveAs(NewFilePath, True)
ThisApplication.SilentOperation = False
'ERROR OCCURS BELOW
Dim fd As DocumentDescriptor
For Each fd In ThisApplication.ActiveEditDocument.ReferencedDocumentDescriptors
If (fd.FullDocumentName = oPartDoc.FullFileName) Then
fd.ReferencedFileDescriptor.ReplaceReference(NewFilePath)
End If
Next
'Update browser names
'UBN()
End Sub
End Module