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

This code will partially do what you want, based upon the assumption that the browser nodes in your assembly are the same as the part number (which they usually are by default):

 

If you can create a simple vba userform with a textbox and button within the VBA editor, then insert this code into the button click action.

This code will look through all levels of the assembly and DELETES ALL the components it comes across that DO NOT MATCH what was typed into the textbox. So I would advise saving or creating a copy of the assembly you want to purge before doing anything further.

 

hopefully this will be of some use to you, or at least give you a starting point as I haven't had a huge amount of time to debug this thoroughly.

 

Private Sub CommandButton1_Click()
    ' Get the active assembly.
    Dim oAsmDoc As AssemblyDocument
    Set oAsmDoc = ThisApplication.ActiveDocument

    ' Get the assembly component definition.
    Dim oAsmDef As AssemblyComponentDefinition
    Set oAsmDef = oAsmDoc.ComponentDefinition

    ' Get all of the leaf occurrences of the assembly.
    Dim oLeafOccs As ComponentOccurrencesEnumerator
    Set oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences

    ' Iterate through the occurrences and print the name.
    Dim oOcc As ComponentOccurrence
   
    For Each oOcc In oLeafOccs
       
   
        'Delete the parts that don't match
        Dim oName As String
        Dim strOrig As String
        Dim Ref1 As String
        Dim L As Integer
       
        strOrig = oOcc.name
        Ref1 = Left(strOrig, InStr(strOrig, ":"))
        L = Len(Ref1) - 1
   

        If Ref1 <> TextBox1.Text & ":" Then
       
 
           
            oOcc.Delete

           
           
         End If
    Next
End Sub