If you don't think that iLogic snippet will work for you needs, there are multiple other ways to delete a component from within a sub assembly, from the main assembly. If you don't want to have to specify the sub assembly's browser node name, and/or don't want to have to specify the component's browser node name, we may be able to identify them in other ways too. Just let us know how you would like to find/identify the component.
Here is another fairly simple iLogic rule code you could use, that also allows you to identify them by their browser node names.
Dim oADoc As AssemblyDocument = ThisDoc.Document
oOccs = oADoc.ComponentDefinition.Occurrences
'<<< specify the name of the sub assembly that your part is within >>>
'the name shown in the 'Model Browser' of the main assembly for it
oSubAsmOcc = oOccs.ItemByName("SubAssem1:1")
'<<< specify the name of the component within that sub assembly >>>
'the name shown in the 'Model Browser' of the main assembly for it
oSubOcc = oSubAsmOcc.Definition.Occurrences.ItemByName("P00022235:5")
Try
oSubOcc.Delete
'oSubOcc.Delete2(True)
Catch oEx As Exception
MsgBox("Component Deletion Failed." & vbCrLf & _
oEx.Message & vbCrLf & oEx.StackTrace,vbExclamation,"iLogic")
End Try
Dim oSubAsmDoc As Document = oSubAsmOcc.Definition.Document
oSubAsmDoc.Update 'or oSubAsmDoc.Update2(True)
oADoc.Update 'or oADoc.Update2(True)
Keep in mind that the component you are trying to delete is in another assembly document, and there may be constraints, representations, model states, or other types of dependencies on, or references to that component within that other assembly that might complicate your ability to delete it.
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS
Wesley Crihfield

(Not an Autodesk Employee)