Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Save drawing document as AutoCAD dwg

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
sthambir
1468 Views, 4 Replies

Save drawing document as AutoCAD dwg

Hi,

 

I'm creating a drawing document and using the API to save it to AutoCAD DWG. What is the correct way to save? 

 

  drawingDoc.SaveAs("AutoCAD_DWG_ModelViews.dwg", false);

 

If the save as parameter is set to true, the above line of code crashes inventor. 

 

Saving to autocad dwg will certainly remove the link to the model. But, how can I do an export to autocad dwg through code? What method should be used?

 

Appreciate any help.

 

Thanks!

4 REPLIES 4
Message 2 of 5
santoshr0114
in reply to: sthambir

Hi sthambir,

The below code VBA works for me.

Dim oDocument As Document
Set oDocument = ThisApplication.ActiveDocument
Call oDocument.SaveAs("D:\AutoCAD_DWG_ModelViews.dwg", True)

Regards
Santosh
Regards
Santosh
Message 3 of 5
sthambir
in reply to: santoshr0114

Thanks for the reply Santhosh. However, as I mentioned in my original email, setting the 2nd boolean parameter to true crashes inventor without a reason. I want to understand under what circumstance does that happen?

Message 4 of 5
santoshr0114
in reply to: sthambir

There is a initial configuration which has to be done before saving(i.e., Exporting) IDW to AutoCADDWG. That configuration has to be set first. If that is not set there might be a possibilty of crash. This Configuration Windows popsUp automatically if not running in Silent Mode.

 

There is a simple VBA sample using Translator in the API help. This might help you get started

 

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

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

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

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

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

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

        Dim strIniFile As String
        strIniFile = "D:\tempDWGOut.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 = "D:\tempdwgout.dwg"

    'Publish document.
    Call DWGAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End Sub

Regards
Santosh
Message 5 of 5
sthambir
in reply to: santoshr0114

Thanks for the code snippet. Even after setting up the ini file and using your code block caused inventor to crash. However, I managed to figure it out when the crash happens. In my case, inventor is invisible and running in silent mode. So, while opening the assembly document to create views, I open the .iam by setting the visible parameter to false. In this case, Inventor crashes while it tries to save the drawing as an autocad dwg file. However, setting the visible parameter of the assembly document to true (Inventor is still invisible and running in silent mode) makes it work smoothly. This could be a bug but my issue is resolved.

 

Much appreiate your support. Thanks.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report