Some new functionality in Inventor 2012 is the ability to save 3D part and assembly models to a DWG file. Ok, this isn’t exactly new but the previous way to do it was a bit of a workaround by using the AEC Exchange application (now known as BIM Exchange) to create the DWG file. In Inventor 2012 the DWG translator has been expanded to support 3D so you can use the Save Copy As command and select “AutoCAD DWG Files” as the file type. In the options dialog you can choose which of the following types to write out; Solid, Surface, or Sketch. You can also specify which version of DWG you want to create; 2000, 2004, 2007, or 2010.
It’s also possible to do the same thing through the API by controlling the DWG translator add-in as shown below. The result of running the VBA macro below is that it will save the solids in the active part or assembly as an AutoCAD 2010 DWG file called “C:\Temp\DWGOutTest.dwg”. The options are documented in the comments.
<
p style=”line-height: 140%;font-family: courier new;background: #eeeeee;color: black;font-size: 8pt”>Public Sub SaveCopyAsDWG3D()
‘ Get the DWG translator Add-In.
Dim DWGAddIn As TranslatorAddIn
Set DWGAddIn = ThisApplication.ApplicationAddIns.ItemById( _
"{C24E3AC2-122E-11D5-8E91-0010B541CD80}")
‘ Get the active document. Can be either a part or assembly.
Dim doc As Document
Set doc = ThisApplication.ActiveDocument
Dim transObjs As TransientObjects
Set transObjs = ThisApplication.TransientObjects
‘ Set up the context to define an output file.
Dim context As TranslationContext
Set context = transObjs.CreateTranslationContext
context.Type = kFileBrowseIOMechanism
‘ Get the available options from the translator.
Dim options As NameValueMap
Set options = transObjs.CreateNameValueMap
If DWGAddIn.HasSaveCopyAsOptions(doc, context, options) Then
‘ Set the options for what types of data to write out.
options.Value("Solid") = True ‘ Output solids.
options.Value("Surface") = False ‘ Output surfaces.
options.Value("Sketch") = False ‘ Output sketches.
‘ Set the DWG version.
‘ 23 = ACAD 2000
‘ 25 = ACAD 2004
‘ 27 = ACAD 2007
‘ 29 = ACAD 2010
options.Value("DwgVersion") = 29
End If
‘ Set the output filename, using a DataMedium object.
Dim oDataMedium As DataMedium
Set oDataMedium = transObjs.CreateDataMedium
oDataMedium.filename = "c:\temp\DWGOutTest.dwg"
‘ Call the SaveCopyAs method of the translator add-in.
Call DWGAddIn.SaveCopyAs(doc, context, options, oDataMedium)
End Sub

Leave a Reply