Hi @CalvinDay. This is a fairly complex situation to write code for. Do you intend to permanently change 'other' part document by adding the cut/extrude feature to that other part document, or do you intend for the feature to only exist within the main assembly?
I had an example assembly to test on, where a top part had a hole through it, top to bottom, and I wanted to extend that hole down through the bottom part that it was constrained to. I wrote an iLogic rule to do that. To make it easier for me, I edited both part documents by assigning names to geometry I was going to be working with. I named the bottom edge of the hole in the top part "Bottom Hole Edge", and named the top face of the bottom part "Top Face". This makes it much easier for me to find/get them by code. And since I knew the exact names of the components I wanted to work with, I specified them by their names directly, instead of using Pick command or something else. In the code, I dug down to the PartDocument object that each component represents, then used the NamedEntities interface to retrieve the named geometry from them. Then accessed the proxy version of those geometries, which exists in the context of the main assembly's model space. Then I entered into Edit Mode of the destination component, so that further edits would effect it. Then I created a new PlanarSketch within the destination part, on the destination parts actual face. Then I accessed that sketch's Proxy within the assembly, and used that to project the proxy source geometry to this proxy sketch. That also creates the 'real' geometry within the 'real' sketch in the part, because I am in Edit Mode of the component. Then, due to application options settings, where projected geometry is 'contruction' by default, I looped through the sketches geometry and changed all construction geometry to regular geometry, so that it can be used for an extrusion profile. Then I generated the Profile object that the extrusion feature needs. Then I created the extrusion definition, set its extent data, and created the extrude feature. Then I update the destination part, exit Edit Mode of the component, and update the main assembly.
Here is the code I used in this example. Hopefully this will help you reach your goal too.
Sub Main
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oOccs As ComponentOccurrences = oADef.Occurrences
Dim oAuto As IiLogicAutomation = iLogicVb.Automation
'get source geometry (the named bottom edge of a round hole, in this example)
Dim oSourceOcc As ComponentOccurrence = oOccs.ItemByName("Part1:1")
Dim oSourceDef As PartComponentDefinition = oSourceOcc.Definition
Dim oSourcePDoc As PartDocument = oSourceDef.Document
Dim oSourceNEs As NamedEntities = oAuto.GetNamedEntities(oSourcePDoc)
Dim oSourceCircleEdge As Edge = oSourceNEs.TryGetEntity("Bottom Hole Edge")
If IsNothing(oSourceCircleEdge) Then
MsgBox("Could not find named circle edge in source part.", vbCritical, "")
Exit Sub
End If
Dim oSourceCircleEdgeProxy As EdgeProxy = Nothing
'this sets a value to the oSourceCircleEdgeProxy variable (gets geometry in context of main assembly)
oSourceOcc.CreateGeometryProxy(oSourceCircleEdge, oSourceCircleEdgeProxy)
'get destination Face to transfer source geometry to (named Top Face of other part in this example)
Dim oDestinationOcc As ComponentOccurrence = oOccs.ItemByName("TestPart1:1")
Dim oDestinationDef As PartComponentDefinition = oDestinationOcc.Definition
Dim oDestinationPDoc As PartDocument = oDestinationDef.Document
Dim oDestinationNEs As NamedEntities = oAuto.GetNamedEntities(oDestinationPDoc)
Dim oDestinationFace As Face = oDestinationNEs.TryGetEntity("Top Face")
If IsNothing(oDestinationFace) Then
MsgBox("Could not find named circle edge in source part.", vbCritical, "")
Exit Sub
End If
Dim oDestinationFaceProxy As FaceProxy = Nothing
'this sets a value to the oSourceCircleEdgeProxy variable (gets geometry in main assembly)
oDestinationOcc.CreateGeometryProxy(oDestinationFace, oDestinationFaceProxy)
'now transfer source geometry to destination face
oDestinationOcc.Edit
'create a sketch within the Part, on the destination face
Dim oSketch As PlanarSketch = oDestinationDef.Sketches.Add(oDestinationFace, False)
'get this sketch in the context of the main assembly
Dim oSketchProxy As PlanarSketchProxy = Nothing
oDestinationOcc.CreateGeometryProxy(oSketch, oSketchProxy)
'now transfer the proxy edge geometry to the proxy sketch
oSketchProxy.AddByProjectingEntity(oSourceCircleEdgeProxy)
'need to make geometry non-construction, so it can be used for an Extrusion Feature
For Each oSE As SketchEntity In oSketch.SketchEntities
If oSE.Construction Then oSE.Construction = False
Next
Dim oProfile As Profile = oSketch.Profiles.AddForSolid()
Dim oExtFeats As ExtrudeFeatures = oDestinationDef.Features.ExtrudeFeatures
Dim oExtDef As ExtrudeDefinition = oExtFeats.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kCutOperation)
oExtDef.SetThroughAllExtent(PartFeatureExtentDirectionEnum.kNegativeExtentDirection)
Dim oExtFeat As ExtrudeFeature = oExtFeats.Add(oExtDef)
If oDestinationPDoc.RequiresUpdate Then oDestinationPDoc.Update
oDestinationOcc.ExitEdit(ExitTypeEnum.kExitToTop)
If oADoc.RequiresUpdate Then oADoc.Update
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield

(Not an Autodesk Employee)