CATIA VBA(VBS) 二次开发中选择集的复制粘贴
在CATIA VBA(VBS)二次开发中可以使用Copy、PasteSpecial方法对选择集进行复制粘贴。示例代码如下:
Sub CATMain()
Dim Doc, Prt, SF, Slct, BodyO, BodyN
Set Doc = CATIA.ActiveDocument
Set Prt = Doc.Part
Set Slct = Doc.Selection
Dim Status, lType(0)
lType(0) = "Body"
Status = Slct.SelectElement2(lType,"Select the body to be copy", True)'这里是让用户选择实体
If Status = "Redo" Or Status ="Undo" Or Status = "Cancel" Then
Exit Sub
End If
Set BodyO = Slct.Item(1).Value'获取用户选择的实体
Slct.Copy
Slct.Add Prt
Slct.PasteSpecial("CATPrtResultWithOutLink")'复制目标实体,然后以AsResult的方式粘贴一个副本实体出来
Set BodyN = Slct.Item(1).Value
BodyN.Name = BodyO.Name &"_www.leanwind.com"'副本实体的命名
Slct.Clear
Prt.InWorkObject = BodyN
End Sub
代码运行结果如下:

PasteSpecial方法采用的粘贴格式如下:
(1)通用格式
"CATIA_LINK_FORMAT" to paste"Catia Link Source",
"OLE_LINK_FORMAT" to paste"Ole Link Source",
"OLE_EMBED_FORMAT" to paste"Ole Embed Source".
(2)在Part中
"CATPrtCont" to paste "AsSpecified In Part Document",
"CATPrtResultWithOutLink" topaste "AsResult",
"CATPrtResult" to paste"AsResultWithLink",
"CATMaterialCont" to paste"As material",
"AsMaterialLink" to paste"As material link",
"CATMechProdCont" to paste"As specified in Assembly",
"CATProdCont" to paste "Asspecified in Product Structure",
"CATIA_SPEC" to paste"CATIA_SPEC",
"CATIA_RESULT" to paste"CATIA_RESULT".
(3)在Product中
"CATProdCont" to paste "Asspecified in Product Structure",
"CATSpecBreakLink" to paste"Break Link".
(4)在Catalog中
"CATDescriptionFormat" to paste"As defined in catalog instanciation",
"CATCtlgChapterFormat" to paste"As defined in catalog document".