CATIA在VBA(VBS)二次开发中使用HybridShapeFactory创建标准图形曲面的方法
下面以一个球形曲面的创建为例,介绍在CATIA中使用VBA(VBS)进行二次开发时通过HybridShapeFactory类创建标准图形曲面的方法。示例代码如下:(代码中有关对象选择的详细介绍可参考文章《CATIA使用VBA(VBS)二次开发时用户的交互选择》。)
Sub catmain()
Dim iSelection
Set iSelection =CATIA.ActiveDocument.Selection
Dim iStatus, iType(0)
Dim iHB,iHSF,iPoint,iRadius,iSphere
'选择中心点
iType(0) = "HybridShape"
iStatus = iSelection.SelectElement2(iType,"Please select the Point", False)
If iStatus = "Redo" Or iStatus ="Undo" Or iStatus = "Cancel" Then
Exit Sub
End If
Set iPoint=iSelection.Item2(1).Value
'选择放置曲面的Geometricalset部件集
iType(0) = "HybridBody"
iStatus = iSelection.SelectElement2(iType,"Please select the Geometrical Set", False)
If iStatus = "Redo" Or iStatus ="Undo" Or iStatus = "Cancel" Then
Exit Sub
End If
Set iHB=iSelection.Item2(1).Value
'输入半径
iRadius = InputBox("Please inputradius", "Radios", 3)
Set iHSF =CATIA.ActiveDocument.Part.HybridShapeFactory
'创建球形曲面
Set iSphere = iHSF.AddNewSphere(iPoint,Nothing, iRadius, -45, 45, 0, 180)
iSphere.Limitation = 1
'将曲面添加到元素集
iHB.AppendHybridShape iSphere
'曲面命名
iSphere.Name = iPoint.Name &"_www.leanwind.com"
iSelection.Clear
CATIA.ActiveDocument.Part.Update
End Sub
创建效果如下所示:
