Configure Options of SaveAs DWG of Part or Assembly

<?xml encoding=”UTF-8″>By Xiaodong Liang

Question:
When we export document to DWG, the options are provided with an *,ini file. It works well with the DrawingDocument. While when saving as part/assembly file to DWG, there are some other options.

But it looks *.ini file does not work with Part or Assembly. How can we configure them?

image

 

Solution:

Those additional options can be explicitly appended to Option array. The code below is a demo. 

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
<font>If oDocument.DocumentType = kPartDocumentObject Or oDocument.DocumentType = kAssemblyDocumentObject Then
oOptions.Value("Solid") = True
oOptions.Value("Surface") = True
oOptions.Value("Sketch") = True
oOptions.Value("DwgVersion") = 31
End If</font>
If oDocument.DocumentType = kDrawingDocumentObject Then
Dim strIniFile As String
strIniFile = "C:tempDWGOut.ini"
' Create the name-value that specifies the ini file to use.
oOptions.Value("Export_Acad_IniFile") = strIniFile
End If
End If
'Set the destination file name
oDataMedium.FileName = "c:tempdwgout.dwg"
'Publish document.
Call DWGAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End Sub

Comments

2 responses to “Configure Options of SaveAs DWG of Part or Assembly”

  1. Reg Hasell Avatar
    Reg Hasell

    Hi
    Thank you, I have made a small change, as for some reason or other the version did not work, and all my exports were @AC1032 (Ver2018) Placing the version at the top of the options list worked?
    If oDocument.DocumentType = kPartDocumentObject Or oDocument.DocumentType = kAssemblyDocumentObject Then
    ‘Acad 2010 = 29
    ‘Acad 2013 = 31
    ‘Acad 2018 = 32
    oOptions.Value(“DwgVersion”) = 31
    oOptions.Value(“Solid”) = True
    oOptions.Value(“Surface”) = False
    oOptions.Value(“Sketch”) = False
    End If
    Regards
    Reg.

  2. Is there also a way to use a template .dwg for exporting a 3D dwg?

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading