Inventor 2022 VBA- Export to/ Save as PDF, DXF, etc sample files are throwing runtime errors

Inventor 2022 VBA- Export to/ Save as PDF, DXF, etc sample files are throwing runtime errors

amarshallQMMYP
Contributor Contributor
1,006 Views
2 Replies
Message 1 of 3

Inventor 2022 VBA- Export to/ Save as PDF, DXF, etc sample files are throwing runtime errors

amarshallQMMYP
Contributor
Contributor

Hello, I was planning to use the VBA code sample files for exporting/saving to different file types as a base for my own code, however I'm running into problems with the unchanged sample programs. As I am not familiar with these translator add ins I'm not really sure how to diagnose the issue beyond confirming that the translator add in was active and the sample inputs matched the SaveCopyAs() method's inputs. When running: 

 

Public Sub ExportToSTEP()
    ' Get the STEP translator Add-In.
    Dim oSTEPTranslator As TranslatorAddIn
    Set oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById({90AF7F40-0C01-11D5-8E83-0010B541CD80}")

    If oSTEPTranslator Is Nothing Then
        MsgBox "Could not access STEP translator."
        Exit Sub
    End If

    Dim oContext As TranslationContext
    Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
    Dim oOptions As NameValueMap
    Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap
    If oSTEPTranslator.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, oContext, oOptions) Then
        ' Set application protocol.
        ' 2 = AP 203 - Configuration Controlled Design
        ' 3 = AP 214 - Automotive Design
        oOptions.Value("ApplicationProtocolType") = 3

        ' Other options...
        'oOptions.Value("Author") = ""
        'oOptions.Value("Authorization") = ""
        'oOptions.Value("Description") = ""
        'oOptions.Value("Organization") = ""

        oContext.Type = kFileBrowseIOMechanism

        Dim oData As DataMedium
        Set oData = ThisApplication.TransientObjects.CreateDataMedium
        oData.FileName = "C:\temptest.stp"

        Call oSTEPTranslator.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData)
    End If
End Sub

 

(this code is the provided sample program for export to STEP file) with a part .ipt file open in inventor the end result is a runtime error '-2147467259 (80004005)': Method 'SaveCopyAs' of object 'TranslatorAddIn' failed. 

 

I would appreciate any help in understanding why I'm getting this error. Thank you. 

 
 

 

0 Likes
Accepted solutions (1)
1,007 Views
2 Replies
Replies (2)
Message 2 of 3

Michael.Navara
Advisor
Advisor
Accepted solution

May be this is some security reason, but you can NOT export file directly to C:\

Modify following line and ensure the "C:\Temp" directory.

 

oData.FileName = "C:\temp\test.stp"

 

Message 3 of 3

amarshallQMMYP
Contributor
Contributor

@Michael.Navara Thank you for your assistance, I'm not sure that I would have been able to realize that on my own. I'll try to notify someone that the export/ savecopyas sample files have a typo. Have a nice day!

0 Likes