Exception from HRESULT: 0x80070057 (E_INVALIDARG) on Export IDW to DWG

Exception from HRESULT: 0x80070057 (E_INVALIDARG) on Export IDW to DWG

Maxim-CADman77
Advisor Advisor
316 Views
4 Replies
Message 1 of 5

Exception from HRESULT: 0x80070057 (E_INVALIDARG) on Export IDW to DWG

Maxim-CADman77
Advisor
Advisor

I'd like to know why code 'Save as DWG Translator Sample' from the Inventor API Help (see below the iLogic edition) generates Exception from HRESULT: 0x80070057 (E_INVALIDARG) on the attached IDW? 

' Public Sub PublishDWG()
    ' Get the DWG translator Add-In.
    Dim DWGAddIn As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")

    'Set a reference to the active document (the document to be published).
    Dim oDocument As Document = ThisApplication.ActiveDocument

    Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
    oContext.Type = kFileBrowseIOMechanism

    ' Create a NameValueMap object
    Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap

    ' Create a DataMedium object
    Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium

    ' Check whether the translator has 'SaveCopyAs' options
    If DWGAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then

        Dim strIniFile As String
        strIniFile = "C:\temp\DWGOut.ini"
        ' Create the name-value that specifies the ini file to use.
        oOptions.Value("Export_Acad_IniFile") = strIniFile
    End If

    'Set the destination file name
    oDataMedium.FileName = "c:\tempdwgout.dwg"

    'Publish document.
    Call DWGAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) ' The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
' End SubPS:

 

Dear @MjDeck could you, please, study this?

 

PS:

The issue was reproduced on Inventor 2024.3.3 and 2025.2.1.

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Accepted solutions (2)
317 Views
4 Replies
Replies (4)
Message 2 of 5

Maxim-CADman77
Advisor
Advisor

Have tried to debug original VBA edition*:

MaximCADman77_1-1734645051247.png

 

Any hint regarding what to look at?

 

Can the issue be because of no "C:\temp\DWGOut.ini" file on my PC?

Should it be there?

 

I believe there is a typo in destination file name line ("\" is skipped) yet it is not the reason of the issue.

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 3 of 5

Maxim-CADman77
Advisor
Advisor
Accepted solution

Solution is here

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 4 of 5

Maxim-CADman77
Advisor
Advisor

I wonder why export of 3Dmodel to DWG does not require an ini file?

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 5 of 5

MjDeck
Autodesk
Autodesk
Accepted solution

Hi @Maxim-CADman77 - export of a 3D model to a DWG does not produce a full drawing. It makes a DWG file that contains solids, surfaces, and/or sketches. You can see this in the Inventor UI.
If you export a drawing to DWG, you will see a sequence of two dialogs with options. On the second dialog, you can save the options to an ini file. That's the same file that can be used by the API. Most of its options have to do with drawings.
If you use the UI to export a part or assembly to DWG, you don't see those options. All you see is checkboxes for Solids, Surfaces, and Sketches and the AutoCAD version.

When you export a part or assembly by the API, the "Export_Acad_IniFile" is just ignored. But you can set the other options as shown here:
https://modthemachine.typepad.com/my_weblog/2011/05/saving-3d-dwg-using-the-dwg-translator.html
and here:
https://adndevblog.typepad.com/manufacturing/2016/07/configure-options-of-saveas-dwg-of-part-or-asse...

Those are pretty old examples. To output with the latest supported version of AutoCAD, just leave out the "DwgVersion" option or (for Inventor 2025) set

oOptions.Value("DwgVersion") = 33




Mike Deck
Software Developer
Autodesk, Inc.

0 Likes