将DWG特定层导入到草图

来源:互联网 发布:淘宝宝贝上架时间 编辑:程序博客网 时间:2024/05/16 11:38

API提供了DWG  Translator addin,用来将DWG导入到Inventor文件。其中提供了多个可选项,以控制在导入时的设置。从2013开始,多了一个选项SelectedLayers,用来指定导入哪些层的实体。用法很简单,例如,导入单个层 
oOptions.Add "SelectedLayers", "Layer1"
导入多个层:
oOptions.Add "SelectedLayers", "Layer1,Layer2"  

以下是一个简单的代码样例。它在零件文档新建一个草图,将一个DWG文件中Layer1层的实体导入

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




原创粉丝点击