本文为微信公众号:“CATIA那点事儿”原创
常用的做法如下:
将目标实体复制一个副本(As Result)
用曲面切目标实体,保留A侧
用曲面切副本实体,保留B侧
通过以上的步骤,我们即可达到切割实体保留双侧的目的。
上述操作可通过VBScript代码实现
Sub CATMain()
Dim Doc, Prt, SF, Slct, BodyO, BodyN
Set Doc = CATIA.ActiveDocument
Set Prt = Doc.Part
Set SF = Prt.ShapeFactory
Set Slct = Doc.Selection
Dim Status, lType(1)
lType(0) = "Body"
lType(1) = "Body"
Status = Slct.SelectElement2(lType, "Select the body to be split", True)'这里是让用户选择目标实体
If Status = "Redo" Or Status = "Undo" Or Status = "Cancel" Then
Exit Sub
End If
Set BodyO = Slct.Item(1).Value'获取用户选择的实体
Slct.Clear
lType(0) = "Plane"
lType(1) = "BiDim"
Status = Slct.SelectElement2(lType, "Select the split surface", False)'让用户选择切割元素(或者叫刀更形象)
If Status = "Redo" Or Status = "Undo" Or Status = "Cancel" Then
Exit Sub
End If
Dim Ref
Set Ref = Slct.Item(1).Value'获取用户选择的“刀”
Slct.Clear
Slct.Add BodyO
Slct.Copy
Slct.Clear
Slct.Add Prt
Slct.PasteSpecial ("CATPrtResultWithOutLink")'上面这波是复制目标实体,然后以As Result的方式粘贴一个副本实体出来
Set BodyN = Slct.Item(1).Value
BodyN.Name = BodyO.Name & "_1"'副本实体的命名在源实体的名字基础上加个“_1”
Slct.Clear
Prt.InWorkObject = BodyO
Dim Split
Set Split = SF.AddNewSplit(Ref, catPositiveSide)'这波是切原实体,保留A侧
Prt.InWorkObject = BodyN
Set Split = SF.AddNewSplit(Ref, catNegativeSide)'这波是切副本实体,保留另一侧
Prt.Update
End Sub |