How to copy geometrical sets from one part to another ?

Nicolas C

How to copy geometrical sets from one part to another ?

Hello,

I'm trying to save by code (CATVBA macro) a Part as a new Part document. I do not want to use the SaveAs method since I do not want to modify the current product structure, so I create a new PartDocument and I try to copy the previous Part content I want into the new one. Here is what I have so far:

Public Sub CopyFromDocToDoc(iMainDoc As Document, iFromPart As Part, iToPartDoc As PartDocument)
Dim i As Integer
iMainDoc.Activate

Dim sel As Selection: Set sel = iMainDoc.Selection
sel.Clear
For i = 1 To iFromPart.HybridBodies.Count
sel.Add iFromPart.HybridBodies.Item(i)
Next
sel.Copy
sel.Clear
iToPartDoc.Activate
iToPartDoc.Part.InWorkObject = iFromPart.MainBody
iToPartDoc.Selection.Paste
End Sub

The issue is when getting to the "sel.Copy" line, I have an error: "Method 'Copy' of object 'Selection' failed".

The error is not very explicit enough to point out the issue...

 

Does anyone has an idea of the problem here ?