文章目录
1.坐标系的可见性
(1)坐标系的对象
注:可以下载英文语言包,安装到现有的inventor,查看英文版的界面,更有利于我们对照编程
英文 | 中文 |
---|---|
Plane | 面 |
Axis | 轴 |
Point | 点 |
2D Sketch | 二维草图 |
3D Sketch | 三维草图 |
(2)坐标系中的对象关系
(3)坐标系中的常用方法属性
- WorkPlane.Delete( [*RetainDependents*] As Boolean ) 删除方法
- WorkPlane.Name() As String 名字属性
- WorkPlane.Visible() As Boolean 可见性属性
- WorkPlanes.Count() As Long 所有工作平面的个数属性
- WorkPlanes.Item( *Index* As Variant ) As WorkPlane 可迭代属性
注:对于WorkAxes 和 WorkPoints也具有同样的方法属性
(4)例子
功能:按下Button11按钮,依次显示工作平面的名字,并且使第三个平面可见
注:对于WorkAxes 和 WorkPoints也具有同样的操作
Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
'定义模型树的对象变量
Dim partDef As PartComponentDefinition
partDef = _invApp.ActiveDocument.ComponentDefinition
'遍历所有对象的
Dim num As Integer
num = partDef.WorkPlanes.Count '获取个数
For i = 1 To num
MsgBox("该文件有平面" & num & "个," & "其中" & partDef.WorkPlanes.Item(i).Name & "是第" & i & "个。")
Next
'设置第二个平面被删除,坐标系的平面不可删除
'partDef.WorkPlanes.Item(2).Delete()
'设置第三个平面可见
partDef.WorkPlanes.Item(3).Visible = True
End Sub
2.二维草图的基本操作
(1)原文
PartComponentDefinition.Sketches Property
Parent Object: PartComponentDefinition
Description
Gets the PlanarSketches collection object that encapsulates all of the planar sketches defined in this ComponentDefinition.
Syntax
PartComponentDefinition.Sketches() As PlanarSketches
PlanarSketches Object
Description
The PlanarSketches collection object provides access to all of the objects and provides methods to create additional PlanarSketch objects. See the article in the overviews section.
(2)主要方法和属性
Sketches(PlanarSketches)
Name | Description |
---|---|
Add()方法 | 创建一个新的二维草图 |
Count 属性 | 返回该集合里的草图个数 |
Item属性 | 允许通迭代的方式访问每一个成员 |
Sketche(PlanarSketche)
Name | Description |
---|---|
Delete() | 删除方法 |
Edit() | 使得草图位于编辑状态方法 |
ExitEdit() | 使得草图退出编辑状态方法 |
name | 名字属性 |
Visible | 可见性属性 |
(3)封装代码
Private Sub New2DSketch()
partDef = inventorApp.ActiveDocument.ComponentDefinition
'创建一个二维草图
Dim sketch1 As PlanarSketch
sketch1 = partDef.Sketches.Add(partDef.WorkPlanes.Item(3))
'草图的状态处于编辑状态
sketch1.Edit()
End Sub
3.三维草图的基本操作
(1)原文
PartComponentDefinition.Sketches3D Property
Parent Object: PartComponentDefinition
Description
Property that returns the Sketches3D collection object that encapsulates all of the 3D sketches defined in this ComponentDefinition.
Syntax
PartComponentDefinition.Sketches3D() As Sketches3D
Sketch3D Object
Description
The Sketch3D object provides access to the current contents of a specific 3D sketch and its related properties and methods. See the article in the overviews section.
(2)主要方法和属性
Sketches3D
Name | Description |
---|---|
Add()方法 | 创建一个新的三维草图 |
Count 属性 | 返回该集合里的草图个数 |
Item属性 | 允许通迭代的方式访问每一个成员 |
Sketch3D
Name | Description |
---|---|
Delete() | 删除方法 |
Edit() | 使得草图位于编辑状态方法 |
ExitEdit() | 使得草图退出编辑状态方法 |
name | 名字属性 |
Visible | 可见性属性 |
(3)封装代码
实现:创建一个三维草图
注意:在创建二维草图和三维草图的区别在于,二维草图需要一个平面,而三维草图不需要。
Private Sub New3DSketch()
partDef = inventorApp.ActiveDocument.ComponentDefinition
'创建一个三维草图
Dim sketch1 As PlanarSketch
sketch1 = partDef.Sketches.Add
'草图的状态处于编辑状态
sketch1.Edit()
End Sub