Rename Browser Nodes API?

Rename Browser Nodes API?

amitabhVA4SD
Advocate Advocate
367 Views
2 Replies
Message 1 of 3

Rename Browser Nodes API?

amitabhVA4SD
Advocate
Advocate

Hello All,

 

Is there a direct API to mimic the "Rename Browser Nodes" option without having to loop over all the occurrences and sub occurrences in the tree? I am looking for some Property of the Browser Pane or Inventor Command.

 

 
This is to mainly handle the below issue
amitabhVA4SD_0-1633114532051.png

 

Thanks,

Amitabh Mukherjee

 

0 Likes
368 Views
2 Replies
Replies (2)
Message 2 of 3

JelteDeJong
Mentor
Mentor

I don't think there is a fast way to do this using the browser. But I think that you can do this fast with an occurrence search function. something like this:

Sub Main()
	
    Dim doc As AssemblyDocument = ThisDoc.Document
    Dim occs As IEnumerable(Of ComponentOccurrence) = findAllWhere(doc,
	    Function(occ)
			'Contains' is case sensitive
	        Return occ.Name.Contains("void-vectratest-UB3_4PA_003")
	    End Function)

    Dim i = 1
    For Each occ As ComponentOccurrence In occs
        occ.Name = "test" & i
        i = i + 1
    Next
End Sub


Public Function findAllWhere(doc As AssemblyDocument,
            predicate As Func(Of ComponentOccurrence, Boolean)) As IEnumerable(Of ComponentOccurrence)

    Dim list As IEnumerable(Of ComponentOccurrence) = doc.ComponentDefinition.
        Occurrences.Cast(Of ComponentOccurrence).
        Where(predicate)

    Dim assemblyList As IEnumerable(Of ComponentOccurrence) = doc.ComponentDefinition.
        Occurrences.Cast(Of ComponentOccurrence).
        Where(Function(o) o.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject)

    For Each assOcc As ComponentOccurrence In assemblyList
        If TypeOf assOcc.Definition Is VirtualComponentDefinition Then Continue For
        Dim assDoc As AssemblyDocument = assOcc.ReferencedDocumentDescriptor.ReferencedDocument
        Dim listToAdd As IEnumerable(Of ComponentOccurrence) = findAllWhere(assDoc, predicate)
        list = list.Concat(listToAdd)
    Next
    Return list
End Function

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 3

amitabhVA4SD
Advocate
Advocate

Sorry for the delay in responding and Thank you @JelteDeJong 

This is helpful!

0 Likes