一、启动Inventor
Inventor.Application对象是基于COM开发Inventor的出发点,以下是我封装获取Inventor Application方法:
1 /// <summary>
2 /// 获取InventorApplication对象
3 /// </summary>
4 /// <returns>InventorApplication对象</returns>
5 public static Application GetInventorApp()
6 {
7 Inventor.Application inventorApp = null;
8 try
9 {
10 inventorApp = Marshal.GetActiveObject("Inventor.Application") as Inventor.Application;
11 }
12 catch
13 {
14 var inventorType = Type.GetTypeFromProgID("Inventor.Application");
15 inventorApp = Activator.CreateInstance(inventorType) as Inventor.Application;
16 inventorApp.Visible = true;
17 }
18 return inventorApp;
19 }
二、创建和打开零件文档
(1)创建零件文档
1 PartDocument partDoc = inventorApp.Documents.Add(
2 DocumentTypeEnum.kPartDocumentObject,
3 inventorApp.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject, SystemOfMeasureEnum.kDefaultSystemOfMeasure, DraftingStandardEnum.kDefault_DraftingStandard, null),
4 true) as PartDocument;
(2)打开零件文档
1 PartDocument partDoc = (PartDocument)inventorApp.Documents.Open(fileName,true);
三、创建和打开部件文档
(1)创建部件文档
1 AssemblyDocument asmDoc = inventorApp.Documents.Add(
2 DocumentTypeEnum.kAssemblyDocumentObject,
3 inventorApp.FileManager.GetTemplateFile(DocumentTypeEnum.kAssemblyDocumentObject, SystemOfMeasureEnum.kDefaultSystemOfMeasure, DraftingStandardEnum.kDefault_DraftingStandard, null),
4 true) as AssemblyDocument;
(2)打开部件件文档
1 AssemblyDocument asmDoc = (AssemblyDocument )inventorApp.Documents.Open(fileName,true);