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!
Solved! Go to Solution.
Solved by sthambir. Go to Solution.
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?
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
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.