所需积分: | 免费资料 |
教程格式: | |
文件大小: | 31 MB |
教程介绍
利用vb来做catia的二次开发。这个视频中,讲解了一个小的案例,目的是让大家熟悉一下catia二次开发的流程。
第一步 打开VB,新建一个标准的exe文件
第二步 在工程引用中调出catia的库,要全部选中
第三步 调用模版文件(配套练习文件中已经包括了)。
第四步 添加2个标签,2个文本框,1个按钮,同时复制下面的代码。
Language="VBSCRIPT"
'能创建5个圆柱体的脚本程序。
Sub CATMain()
Set documents1 = CATIA.Documents
Set partDocument1 = documents1.Add("Part")
Set part1 = partDocument1.Part
Set bodies1 = part1.Bodies
Set body1 = bodies1.Item("PartBody")
Dim arrayOfVariantOfDouble1(8)
arrayOfVariantOfDouble1(0) = 0.000000
arrayOfVariantOfDouble1(1) = 0.000000
arrayOfVariantOfDouble1(2) = 0.000000
arrayOfVariantOfDouble1(3) = 1.000000
arrayOfVariantOfDouble1(4) = 0.000000
arrayOfVariantOfDouble1(5) = 0.000000
arrayOfVariantOfDouble1(6) = 0.000000
arrayOfVariantOfDouble1(7) = 1.000000
arrayOfVariantOfDouble1(8) = 0.000000
x=0'先初始化变量
For I = 1 To 5'执行5次循环
Set sketches1 = body1.Sketches
Set originElements1 = part1.OriginElements
Set reference1 = originElements1.PlaneXY
Set sketch1 = sketches1.Add(reference1)
sketch1.SetAbsoluteAxisData arrayOfVariantOfDouble1
part1.InWorkObject = sketch1
Set factory2D1 = sketch1.OpenEdition()
Set geometricElements1 = sketch1.GeometricElements
Set axis2D1 = geometricElements1.Item("AbsoluteAxis")
Set line2D1 = axis2D1.GetItem("HDirection")
line2D1.ReportName = 1
Set line2D2 = axis2D1.GetItem("VDirection")
line2D2.ReportName = 2
Set circle2D1 = factory2D1.CreateClosedCircle(x, 0.000000, 50)
'取消(注释)下面三行,注意行首的单引号
'Set point2D1 = axis2D1.GetItem("Origin")
'circle2D1.CenterPoint = point2D1
'circle2D1.ReportName = 3
sketch1.CloseEdition
part1.InWorkObject = body1
part1.Update
part1.InWorkObject = body1
Set shapeFactory1 = part1.ShapeFactory
Set pad1 = shapeFactory1.AddNewPad(sketch1, 20.000000)
part1.Update
x = x + 125'把圆柱体的位置加125mm
Next'循环体结束
End Sub
第五步 编辑修改代码,调试运行程序
第六步 查看效果,就可以看到,创建的几个圆柱体。