-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path创建实体.bas
56 lines (38 loc) · 1.21 KB
/
创建实体.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
Attribute VB_Name = "创建实体"
Sub CATMain()
On Error Resume Next
Dim oPart As Part
Dim oBodies As Bodies
Dim oBody As Body
Dim oSF As ShapeFactory
Dim oPad As Pad
'利用当前文档
Set oPart = CATIA.ActiveDocument.Part
'如果当前没有文档打开
If Err.Number <> 0 Then
'新建文档
Dim oDoc As Document
Set oDoc = CATIA.Documents.Add("Part")
Set oPart = oDoc.Part
End If
On Error GoTo 0
Set oBodies = oPart.Bodies
Set oBody = oBodies.Item("零件几何体")
'选取参考平面
Dim plnXY As Plane
Set plnXY = oPart.originElements.PlaneYZ
'在参考平面上添加草图
Dim oSketch As Sketch
Set oSketch = oBody.Sketches.Add(plnXY)
'获取Factory2D,利用Factory2D可以创建草图元素(画圆,画直线等)
Dim oFactory2D As Factory2D
Set oFactory2D = oSketch.OpenEdition
'画圆
Dim oCCircle As Circle2D
Set oCCircle = oFactory2D.CreateClosedCircle(-30, -50, 15)
oSketch.CloseEdition
'设置Pad特征的高度为20mm
Set oSF = oPart.ShapeFactory
Set oPad = oSF.AddNewPad(oSketch, 20)
oPart.Update
End Sub