Import specific layers of DWG to inventor part sketch

By Xiaodong Liang

The option SelectedLayout of the Translator Addin of DWG can specify the layers to import to the sketch.

oOptions.Add "SelectedLayers", "Layer1"

you can also specify several layers, e.g.

oOptions.Add "SelectedLayers", "Layer1,Layer2" 

Sub ImportDWGIntoSketch()
    ‘DWG translator
    Dim oDwg As TranslatorAddIn
    Set oDwg = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")
    Dim oData As DataMedium
    Dim oContext As TranslationContext
    Dim oOptions As NameValueMap
    Set oData = ThisApplication.TransientObjects.CreateDataMedium
    Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
    Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap
    ‘ Specify a DWG file to import it into sketch, please change the path name as needed
    oData.FileName = "C:\Temp\mytest.dwg"
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.Documents.Add(kPartDocumentObject)
    ‘add a new sketch
    Dim oSk As PlanarSketch
    Set oSk = oDoc.ComponentDefinition.Sketches.Add(oDoc.ComponentDefinition.WorkPlanes(3))
    oSk.Edit
    oContext.Type = kFileBrowseIOMechanism
    oContext.OpenIntoExisting = oSk

    ‘ Specify the layers to import
  oOptions.Add "SelectedLayers", "Layer1" 
  ‘oOptions.Add "SelectedLayers", "0,Layer2" 
    oOptions.Add "InvertLayersSelection", False ‘ Set if import the selected layers in above setting
    ‘ Set the ConstrainEndPoints
    oOptions.Add "ConstrainEndPoints", True
    ‘ Specify the units of DWG file
    oOptions.Add "FileUnits", "Millimeters"
    Call oDwg.Open(oData, oContext, oOptions, oDoc)
End Sub


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading