@robertast @JhoelForshav
Since you are trying to do this by copying bodies between two part type components of an assembly, to create new features within the second part component, perhaps you could get some pointers from this Sample VBA code that was provided within the online help section, that is dealing with a very similar issue.
It uses a method called ImprintBodies, which is found under ThisApplication.TransientBRep.
Please note too though, that they also mentioned (within the comments of the code) having trouble while attempting to use SurfaceBodyProxy objects, so they chose to show a workaround way to do it.
Perhaps this method will work for your situation, if the other options aren't working.
I had been trying to go at this whole issue from a slightly different perspective, to avoid as much set-up work as possible, such as creating a bunch of invisible solid/surface bodies ahead of time, avoid all the manual selections, by fully automating the task, using NamedEntities to identify the source & target items (faces, edges, etc.), then using something like attributes and/or NameValueMaps to convey their data from one part to the other, to then create the features needed within the target part. (Since naming an entity is essentially adding an Attribute to it, that helps you to uniquely identify it later, it seemed like a logical data storage medium.) Unfortunately, I never got the chance to finish it, so I thought I would just post one variation of the starting portion of this code here, so others can contemplate this idea too.
The initial rather simplistic idea was to name the source and target faces within the part files, then retrieve the source face within the assembly file, transfer the hole center points over to the target face, while also gathering the necessary data about the holes (from attributes or similar), then create the hole features within the target part file using the transferred hole center points and the gathered data (diameters & depths).
Here's the unfinished code I had started.
Sub Main
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("This rule '" & iLogicVb.RuleName & "' only works for Assembly Documents.",vbOK, "WRONG DOCUMENT TYPE")
Return
End If
Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oAuto As IiLogicAutomation = iLogicVb.Automation
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oOccs As ComponentOccurrences = oADef.Occurrences
Dim oOcc As ComponentOccurrence
'Get the Source & Target faces, occs, & definitions
Dim oTOcc,oSOcc As ComponentOccurrence 'Target & Source Occurrences
Dim oTDef,oSDef As PartComponentDefinition 'Target & Source PartComponentDefinitions
Dim oTDoc, oSDoc As PartDocument 'Target & Source PartDocuments
Dim oNE As NamedEntities
Dim oTFace, oSFace As Face 'Target & Source mating Faces (within the parts)
Dim oSDowelHoleFace1, oSScrewHoleFace1 As Face 'Source cylindrical hole named faces
Dim oSDowelHoleFeat, oSScrewHoleFeat As PartFeature
Dim oSDowelHoleDims, oSScrewHoleDims As FeatureDimensions
Dim oTFProxy, oSFProxy As FaceProxy 'Target & Source FaceProxies (within the assembly)
'Could also create variables for hole cylinder named faces here
For Each oOcc In oOccs
If oOcc.Name.Contains("Part 1") Then
oTOcc = oOcc
oTDef = oTOcc.Definition
oTDoc = oTOcc.Definition.Document
'The following face is the one on the target document, where the new hole features will be created.
oTFace = oAuto.GetNamedEntities(oTargetDoc).TryGetEntity("Target Face")
oTOcc.CreateGeometryProxy(oTFace,oTFProxy)
ElseIf oOcc.Name.Contains("Part 2") Then
oSOcc = oOcc
oSDef = oSOcc.Definition
oSDoc = oOcc.Definition.Document
oNE = oAuto.GetNamedEntities(oSourceDoc)
'The following face is the one on the Source document, where the existing holes are.
oSFace = oNE.TryGetEntity("Source Face")
oSScrewHoleFace1 = oNE.TryGetEntity("Screw Hole 1 Cylinder")
oSScrewHoleFeat = oSScrewHoleFace1.CreatedByFeature
' oSScrewHoleDims = oSScrewHoleFeat.FeatureDimensions
oSDowelHoleFace1 = oNE.TryGetEntity("Dowel Hole 1 Cylinder")
oSDowelHoleFeat = oSScrewHoleFace1.CreatedByFeature
' oSDowelHoleDims = oSDowelHoleFeat.FeatureDimensions
oSOcc.CreateGeometryProxy(oSFace,oSFProxy)
End If
Next
'Collect geometry data from the source face holes
Dim oCCount As Integer = 0
Dim oCircle As Circle2d
Dim oDia As Double
Dim oCP As Point2d
For Each oEL As EdgeLoop In oSFProxy.EdgeLoops
If oEL.IsOuterEdgeLoop = False Then
If oEL.Edges.Item(1).GeometryType = CurveTypeEnum.kCircleCurve Then
oCCount = oCCount + 1 'found a circular edge
oCircle = oEL.Edges.Item(1).Geometry
oDia = oCircle.Radius * 2
oCP = oCircle.Center
End If
End If
Next
' 'Collect data about the source cylinder faces
' Dim oScHoleCyl As Cylinder = oSScrewHoleFace1.Geometry
' Dim oScHoleDia As Double = oScHoleCyl.Radius * 2
' Dim oScHoleBPoint As Point = oScHoleCyl.BasePoint
' Dim oDwlHoleCyl As Cylinder = oSDowelHoleFace1.Geometry
' Dim oDwlHoleDia As Double = oDwlHoleCyl.Radius * 2
' Dim oDwlHoleBPoint As Point = oDwlHoleCyl.BasePoint
'Transfer hole center points to sketch on Target face while in-place editing the target part.
' oTOcc.Edit 'not sure if I want to use this, because it will take focus away from the code running
Dim oSketch As PlanarSketch = oTDef.Sketches.Add(oTFace, False)
Dim oScHoleCPoint As SketchPoint = oSketch.AddByProjectingEntity(oScHoleBPoint)
Dim oDwlHoleCPoint As SketchPoint = oSketch.AddByProjectingEntity(oDwlHoleBPoint)
' oTOcc.ExitEdit(ExitTypeEnum.kExitToPrevious)
'Create the HoleFeatures within the Target part
Dim oTHoleFeats As HoleFeatures = oTDef.Features.HoleFeatures
'Create the screw hole feature placement definition
'Need to translate cylinder base point data to define oScHolePoint
Dim oScHolePoint = ThisApplication.TransientGeometry.CreatePoint()
Dim oTScHoleDef As HolePlacementDefinition = oTHoleFeats.CreatePointPlacementDefinition(oScHolePoint,oTFace)
' oTHoleFeats.AddDrilledByDistanceExtent()
End Sub
Wesley Crihfield

(Not an Autodesk Employee)