Code:
Sub CATMain()Dim oHP As Product
Dim oSel As Selection
Dim oSel2 As Selection
Set oHP = CATIA.ActiveDocument.Product
Dim oSourceProd As Product
Dim oTargetProd As Product
Dim InputObjectType(0) As Variant
InputObjectType(0) = "Product"
Set oSel = CATIA.ActiveDocument.Selection
Dim Source As Part
Dim Target As Part
Dim vis As Variant
Dim r As Long
Dim g As Long
Dim b As Long
Dim oBodies As Bodies
Dim oBody As Body
Dim oSF As ShapeFactory
Dim oElems As OriginElements
Dim oSymPlane As HybridShapePlaneExplicit
Dim oRef As Reference
Dim oSym As Symmetry
Dim oHSS As HybridShape
Dim oSourceCol As New VBA.Collection
Dim oTargetCol As New VBA.Collection
Dim oSourceMatrix(11) 'As Variant
Dim oTargetMatrix(11) 'As Variant
Dim oDSel
Set oDSel = oSel
oDSel.Clear
Result = oDSel.SelectElement3(InputObjectType(), "Wybierz party źródłowe", True, CATMultiSelTriggWhenUserValidatesSelection, False)
For i = 1 To oDSel.Count
oSourceCol.Add oDSel.Item(i).Value
Next
oDSel.Clear
Result = oDSel.SelectElement3(InputObjectType(), "Wybierz party docelowe", True, CATMultiSelTriggWhenUserValidatesSelection, False)
For i = 1 To oDSel.Count
oTargetCol.Add oDSel.Item(i).Value
Next
oDSel.Clear
For i = 1 To oSourceCol.Count
'definicja partów: źrodłowego i mirrora
Set Source = oSourceCol.Item(i).Products.Item(1).ReferenceProduct.Parent.Part
Set Target = oTargetCol.Item(i).Products.Item(1).ReferenceProduct.Parent.Part
'kopiowanie body ze żródła
oSel.Clear
oSel.Add Source
CATIA.StartCommand "Open in New Window"
Set oSel = CATIA.ActiveDocument.Selection
oSel.Clear
oSel.Add Source.MainBody
'kopiowanie kolorów
Set vis = oSel.VisProperties
vis.GetRealColor r, g, b
oSel.Copy
oSel.Clear
'zamykam okno Source
CATIA.ActiveWindow.Close
'otwieram okno Target
Set oSel2 = CATIA.ActiveDocument.Selection
oSel2.Clear
oSel2.Add Target
oSel2.PasteSpecial "CATPrtResult"
'nadawanie kolorów
vis.SetRealColor r, g, b, 0
oSel.Clear
Target.Update
'dodawnie symetrii
Set oBodies = Target.Bodies
Set oBody = oBodies.Item(oBodies.Count)
Target.InWorkObject = oBody
Set oSF = Target.ShapeFactory
Set oElems = Target.OriginElements
Set oSymPlane = oElems.PlaneZX
Set oRef = Target.CreateReferenceFromObject(oSymPlane)
Set oSym = oSF.AddNewSymmetry2(oRef)
Set oHSS = oSym.HybridShape
Target.MainBody = oBody
oSel.Add oBodies.Item("PartBody")
oSel.Delete
oSel.Clear
Target.MainBody.Name = "PartBody"
Target.Update
Next
Set oSel = CATIA.ActiveDocument.Selection
End Sub