Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Owner2229
in reply to: mgigliotti

HI, I don't have acces to Inventor right now, as Im at home, so I can't test it.

But did you try something like this below? (made from memory, so you may need to play with the statements - highlighted)

 

The idea in this is to run it for every component (as you do now, I suppose) and every time remove all components but one.

The "FirstComponent" name will come from the body name.

 

Dim oCurrentComponent As String = "FirstComponent" 'Here you should write the name of the first component
oDerivedPrtDef = oFinalCompDef.ReferenceComponents.DerivedPartComponents.CreateDefinition(oPartDoc.FullDocumentName) oFinalCompDef.ReferenceComponents.DerivedPartComponents.Add(oDerivedPrtDef)
Dim oCom As PartComponent
For Each oCom In oFinalCompDef.ReferenceComponents.DerivedPartComponents
MsgBox(oCom.Name) ' For testing purposes
If Not oCom.Name = oCurrentComponent Than
oCom.Remove
End If
Next

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods