Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

VB.net error on ported VBA code

pball
Advisor

VB.net error on ported VBA code

pball
Advisor
Advisor

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

 

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
Reply
445 Views
3 Replies
Replies (3)

Anonymous
Not applicable
0 Likes

pball
Advisor
Advisor
I'm using ThisApplication all over my addin so I don't see how that is the issue.
Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes

pball
Advisor
Advisor
Well this was an easy fix after a bit more searching.

Just replace the loop at the end with the following code, which I found in a thread of mine asking for help while creating this script.

oPart.Replace(NewFilePath, True)
Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes