Renaming Browse Nodes Sequentially

Renaming Browse Nodes Sequentially

cencinaNB2ET
Advocate Advocate
581 Views
3 Replies
Message 1 of 4

Renaming Browse Nodes Sequentially

cencinaNB2ET
Advocate
Advocate

Hi All,

 

I have been trying to rename parts or Assemblies on the browser node for replace commands and other processes.

 

The problem I have is that in order to get the occurrence number ( :1...) I need to access thorough components occurrences, but to change the name i need to access it with referenced documents.

I saw one other method which is the get browser Node from object which is still under occurrences and you can iterate through the numbers... and change the name.

 

But Im not able to separate a certain part and rename them accordingly ( 1 to what ever its present ) i tried setting it to an empty string but it defaults to starting the sequence back to its original 9 to 12 ( there are only 4 pf these parts) please see screen shot:

 

Capture22.PNG

 

So the question remains How do I rename these in sequence? i know its a loop within a loop but I cant seem to get it right.

So i would end Up with LAG Screw :1...... until LAG Screw:4

 

 

 

Many Thanks.

 

0 Likes
Accepted solutions (1)
582 Views
3 Replies
Replies (3)
Message 2 of 4

cencinaNB2ET
Advocate
Advocate
Accepted solution

Sorry it was pretty easy..

 

SyntaxEditor Code Snippet

Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

' Get the model browser
Dim oPane As BrowserPane
oPane = oDoc.BrowserPanes.Item("Model")

' Get the occurrence of the object
Dim oOcc As ComponentOccurrence


i = 0
For Each oOcc In oDoc.ComponentDefinition.Occurrences
Dim oNode As BrowserNode
oNode = oPane.GetBrowserNodeFromObject(oOcc)
'reset name
If Left(oNode.NativeObject.Name,9 ) = "LAG Screw" Then
i = i + 1
MessageBox.Show( oNode.NativeObject.Name, "")
'oNode.NativeObject.Name = ""
oNode.NativeObject.Name =  "LAG Screw" + ":" + CStr(i)
End If
Next
0 Likes
Message 3 of 4

cencinaNB2ET
Advocate
Advocate

Actually.. One more thing

The default browser names, How can I change that to stay whatever I renamed it to be??

 

 

 

0 Likes
Message 4 of 4

Anonymous
Not applicable

Hi,

I did sometimes back to set the Browser node as "Part Number". May be this helps Smiley Tongue

 

--------------------------------------------

Public Sub Rename_Browser_Node()

Dim oDoc As Inventor.AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument

' Get Assembly Component Definition
Dim oCompDef As AssemblyComponentDefinition
Set oCompDef = oDoc.ComponentDefinition

On Error Resume Next

Dim oCompOcc As ComponentOccurrence
For Each oCompOcc In oCompDef.Occurrences
Call RenameOccurence(oCompOcc)
Next

ThisApplication.ActiveDocument.Update
'Call for Rebuild All
'Call for Updating Mass

MsgBox ThisApplication.ActiveDocument.DisplayName & ":" & vbCrLf & vbCrLf + "Browser Renamed as " & "''Part Number''"

End Sub

 

 

Private Sub RenameOccurence(oCompOcc)

' Get the current occurence number in Assembly Browser Eg Part1:17 = 17
Dim sSplit() As String
sSplit = Split(oCompOcc.Name, ":")

' Define Design tracking Properties to get the CAD Filename
Dim oProjectPropertySet As PropertySet
Set oProjectPropertySet = oCompOcc.Definition.Document.PropertySets("Design Tracking Properties")

' Get Occurence Filename
Dim sFullPathFilename As String
Dim sFullFileName As String
Dim sFileName As String
sFullPathFilename = oCompOcc.Definition.Document.FullFileName
sFullFileName = Right(sFullPathFilename, Len(sFullPathFilename) - InStrRev(sFullPathFilename, "\"))
sFileName = Left(sFullFileName, Len(sFullFileName) - 4)

' Rename Assembly Part Occurence with or without assembly occurence number
If UBound(sSplit) > 0 Then
oCompOcc.Name = oProjectPropertySet.Item("Part Number").Value + ":" + sSplit(UBound(sSplit))

Else
oCompOcc.Name = oProjectPropertySet.Item("Part Number").Value

End If

End Sub

 

-----------------------------------------------------

 

Hope this helps

 

 

Regards,

Alex

0 Likes