添加引用:CATIA V5 GSMInterfaces Object Library,只需添加这一个,其余需要的引用会自动添加。
添加引用之后,引用列表里面就会多出这几个库。
导入命名空间:
Imports INFITF Imports HybridShapeTypeLib Imports MECMOD定义变量
Dim CatiaApp As Application ' catia应用 Dim ADoc As Document ' 文件 Dim APart As Part ' 定义零件 Dim ABodies As HybridBodies ' 定义Body集合 Dim ABody As HybridBody ' 定义Body Dim Shapes As HybridShapeFactory ' 定义几何图形集启动Catia函数
' 启动Catia Sub StartupCatia() Dim strStartup As String = "启动CATIA..." Console.WriteLine(strStartup) ' 跳过错误步骤,继续执行 On Error Resume Next CatiaApp = GetObject(, "CATIA.Application") If Err.Number <> 0 Then CatiaApp = CreateObject("CATIA.Application") CatiaApp.Visible = True End If Dim strDoc As String = "新建Part文件..." Console.WriteLine(strDoc) ' 获取当前活动文件;如果没有活动文件,则新建零件 ADoc = CatiaApp.ActiveDocument If ADoc Is Nothing Then Err.Clear() ADoc = CatiaApp.Documents.Add("Part") End If ' 初始化 APart = ADoc.Part ABodies = APart.HybridBodies ABody = ABodies.Add() Shapes = APart.HybridShapeFactory End Sub