我想编写一个宏来选择:
- 所有名为“name_1”的实体并将它们添加到名为“new group 1”的新实体中
- 所有名为“name_2”的实体并将它们添加到名为“new group 2”的新实体中
- 所有名为“name_3”的实体并将它们添加到名为“new group 3”的新实体中
我在我的 CATIA R20 上成功编写了这段代码,并且工作正常。它将所有实体添加到新实体中。但后来我尝试在 CATIA R19 和 R24 上运行宏,但它不起作用!在 R19/R24 中,它不会添加所有名为“name_1”的实体,但它只会在新实体中添加一个实体!
Sub CATMain()
Dim partDocument1 As PartDocument
Set partDocument1 = CATIA.ActiveDocument
Set objSel = partDocument1.Selection
Dim part1 As Part
Set part1 = partDocument1.Part
Dim bodies1 As Bodies
Set bodies1 = part1.Bodies
Set shapeFactory1 = part1.ShapeFactory
Set bodies1 = part1.Bodies
Dim body1 As Body
Set body1 = bodies1.Item("PartBody")
Dim shapes1 As Shapes
Set shapes1 = body1.Shapes
objSel.Clear
'******************name_1*********************
objSel.Search ("Name=name_1,all")
objcount = objSel.Count
Set body1 = bodies1.Add()
body1.Name = "new_name_1"
Set body1 = bodies1.Item("new_name_1")
part1.InWorkObject = body1
For i = 1 To objcount
Set body11 = bodies1.Item("name_1")
Set add1 = shapeFactory1.AddNewAdd(body11)
Next
objSel.Clear
End Sub