Hello,
I want to know how to read the browser nodes index number that is placed behind the display name of each part inside an assembly.
I can not find the best way to do this. Someon any idea?
Hello,
I want to know how to read the browser nodes index number that is placed behind the display name of each part inside an assembly.
I can not find the best way to do this. Someon any idea?
Here is a sample for using the BrowserPane Object Method "GetBrowserNodeFromObject":
Sub Main
If ThisApplication.ActiveDocumentType <> kAssemblyDocumentObject Then MessageBox.Show("This rule is designed to only work in assembly documents.", "Wrong Document Type") : Exit Sub
Dim PickThis As Object = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select a Part")
If IsNothing(PickThis) Then Exit Sub ' If nothing gets selected then we're done
Dim modelBrowser As BrowserPane = ThisApplication.ActiveDocument.BrowserPanes("Model")
Dim ObjectNode As BrowserNode = modelBrowser.GetBrowserNodeFromObject(PickThis)
ObjectNode.EnsureVisible
MessageBox.Show(ObjectNode.BrowserNodeDefinition.Label, "Node Found")
End Sub
It doesn't give an Index number, but gives the node itself. Is that enough for what you want to do with it or do you absolutely need an Index value?
Here is a sample for using the BrowserPane Object Method "GetBrowserNodeFromObject":
Sub Main
If ThisApplication.ActiveDocumentType <> kAssemblyDocumentObject Then MessageBox.Show("This rule is designed to only work in assembly documents.", "Wrong Document Type") : Exit Sub
Dim PickThis As Object = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select a Part")
If IsNothing(PickThis) Then Exit Sub ' If nothing gets selected then we're done
Dim modelBrowser As BrowserPane = ThisApplication.ActiveDocument.BrowserPanes("Model")
Dim ObjectNode As BrowserNode = modelBrowser.GetBrowserNodeFromObject(PickThis)
ObjectNode.EnsureVisible
MessageBox.Show(ObjectNode.BrowserNodeDefinition.Label, "Node Found")
End Sub
It doesn't give an Index number, but gives the node itself. Is that enough for what you want to do with it or do you absolutely need an Index value?
Hello,
I have the PartRunner where i need to find the name remember the :1 or :2 and then change the name to the file name and then place the number :1 or :2 after the name. And then the next one.
So i have the Iteration true all ass and parts but the part to get the node is still not working.
Hello,
I have the PartRunner where i need to find the name remember the :1 or :2 and then change the name to the file name and then place the number :1 or :2 after the name. And then the next one.
So i have the Iteration true all ass and parts but the part to get the node is still not working.
Here try implementing this subroutine into your current code:
Sub Main
If ThisApplication.ActiveDocumentType <> kAssemblyDocumentObject Then MessageBox.Show("This rule is designed to only work in assembly documents.", "Wrong Document Type") : Exit Sub
5: Dim PickThis As Object = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select a Part")
If IsNothing(PickThis) Then Exit Sub ' If nothing gets selected then we're done
'Enter the BrowserNode Sub routine from your loop with a ComponentOccurrence Object and the Main open assembly document
Call ChangeBrowserNode(PickThis, ThisApplication.ActiveDocument)
'Repeatable for testing. Won't need the next line if you are already looping
If MessageBox.Show("Would you like to repeat this code?", "Repeat?", MessageBoxButtons.YesNo) = vbYes Then GoTo 5
End Sub
Sub ChangeBrowserNode(Oc As ComponentOccurrence, Parent As AssemblyDocument)
Dim AllPanes As BrowserPanes = Parent.BrowserPanes
Dim modelBrowser As BrowserPane = AllPanes.Item("Model")
Dim ObjectNode As BrowserNode = modelBrowser.GetBrowserNodeFromObject(Oc)
ObjectNode.EnsureVisible 'Simply to verify correct selection. Can be removed after testing
Dim NameChange As String = ObjectNode.BrowserNodeDefinition.Label
Dim CaptureIndex As Integer = 1
If InStr(NameChange, ":") = 1 Then CaptureIndex = CInt(NameChange.Remove(0, NameChange.LastIndexOf(":") + 1))
Attempt:
Try
NameChange = System.IO.Path.GetFileNameWithoutExtension(Oc.ReferencedDocumentDescriptor.FullDocumentName) & ":" & CaptureIndex
ObjectNode.NativeObject.Name = NameChange
Catch 'Name is in use
CaptureIndex += 1
GoTo Attempt
End Try
End Sub
All it needs is the current ComponentOccurrence In the loop and the Main AssemblyDocument to be fed into it. I have it called from a dummy Main sub you can us for testing before implementation.
Let me know if you have any questions or if it is not working as intended
Here try implementing this subroutine into your current code:
Sub Main
If ThisApplication.ActiveDocumentType <> kAssemblyDocumentObject Then MessageBox.Show("This rule is designed to only work in assembly documents.", "Wrong Document Type") : Exit Sub
5: Dim PickThis As Object = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select a Part")
If IsNothing(PickThis) Then Exit Sub ' If nothing gets selected then we're done
'Enter the BrowserNode Sub routine from your loop with a ComponentOccurrence Object and the Main open assembly document
Call ChangeBrowserNode(PickThis, ThisApplication.ActiveDocument)
'Repeatable for testing. Won't need the next line if you are already looping
If MessageBox.Show("Would you like to repeat this code?", "Repeat?", MessageBoxButtons.YesNo) = vbYes Then GoTo 5
End Sub
Sub ChangeBrowserNode(Oc As ComponentOccurrence, Parent As AssemblyDocument)
Dim AllPanes As BrowserPanes = Parent.BrowserPanes
Dim modelBrowser As BrowserPane = AllPanes.Item("Model")
Dim ObjectNode As BrowserNode = modelBrowser.GetBrowserNodeFromObject(Oc)
ObjectNode.EnsureVisible 'Simply to verify correct selection. Can be removed after testing
Dim NameChange As String = ObjectNode.BrowserNodeDefinition.Label
Dim CaptureIndex As Integer = 1
If InStr(NameChange, ":") = 1 Then CaptureIndex = CInt(NameChange.Remove(0, NameChange.LastIndexOf(":") + 1))
Attempt:
Try
NameChange = System.IO.Path.GetFileNameWithoutExtension(Oc.ReferencedDocumentDescriptor.FullDocumentName) & ":" & CaptureIndex
ObjectNode.NativeObject.Name = NameChange
Catch 'Name is in use
CaptureIndex += 1
GoTo Attempt
End Try
End Sub
All it needs is the current ComponentOccurrence In the loop and the Main AssemblyDocument to be fed into it. I have it called from a dummy Main sub you can us for testing before implementation.
Let me know if you have any questions or if it is not working as intended
I've written a blog post that looks at renaming browser nodes with iLogic, I have included 3 different code samples for slightly different scenarios. Have a look and see if this helps with what you are trying to do.
https://clintbrown.co.uk/2020/07/29/ilogic-normalise-browser-nodes-with-code/
I've written a blog post that looks at renaming browser nodes with iLogic, I have included 3 different code samples for slightly different scenarios. Have a look and see if this helps with what you are trying to do.
https://clintbrown.co.uk/2020/07/29/ilogic-normalise-browser-nodes-with-code/
@J-Camper @Anonymous
Hello,
I managed to make this code:
Sub Main If ThisApplication.ActiveDocumentType <> kAssemblyDocumentObject Then MessageBox.Show("This rule is designed to only work in assembly documents.", "Wrong Document Type") : Exit Sub Dim parentDoc As AssemblyDocument = ThisApplication.ActiveDocument 'Do anything unique to main assembly Call AssemblyRunner(parentDoc) End Sub Sub AssemblyRunner(aDoc As AssemblyDocument) 'Do things to the assembly file if any 'MessageBox.Show(aDoc.DisplayName, "Assembly:") 'Start Looping For Each oOcc As ComponentOccurrence In aDoc.ComponentDefinition.Occurrences If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Dim GetOccName As String = oOcc.Name If GetOccName.Contains(":") Then Dim words As String() = GetOccName.Split(":") oEerst = words(0) oTweede = words(1) 'Dim CurFileName As String 'get the selected item document occurrence name doc = oOcc.Definition.Document 'get the path and file name of the selected item CurFileName = doc.FullFileName 'defines backslash as the subdirectory separator Dim strCharSep As String = System.IO.Path.DirectorySeparatorChar 'find the postion of the last backslash in the path FNamePos = InStrRev(CurFileName, "\", -1) 'get the file name with the file extension Name = Right(CurFileName, Len(CurFileName) - FNamePos) 'get the file name (without extension) ShortName = Left(Name, Len(Name) - 4) 'get the path of the folder containing the file Folder_Location = Left(CurFileName, Len(CurFileName) - Len(Name)) oOcc.Name = ShortName & ":" & words(1) End If Call AssemblyRunner(oOcc.Definition.Document) Else If oOcc.DefinitionDocumentType = kPartDocumentObject Dim GetOccName As String = oOcc.Name If GetOccName.Contains(":") Then Dim words As String() = GetOccName.Split(":") oEerst = words(0) oTweede = words(1) 'Dim CurFileName As String 'get the selected item document occurrence name doc = oOcc.Definition.Document 'get the path and file name of the selected item CurFileName = doc.FullFileName 'defines backslash as the subdirectory separator Dim strCharSep As String = System.IO.Path.DirectorySeparatorChar 'find the postion of the last backslash in the path FNamePos = InStrRev(CurFileName, "\", -1) 'get the file name with the file extension Name = Right(CurFileName, Len(CurFileName) - FNamePos) 'get the file name (without extension) ShortName = Left(Name, Len(Name) - 4) 'get the path of the folder containing the file Folder_Location = Left(CurFileName, Len(CurFileName) - Len(Name)) oOcc.Name = ShortName & ":" & words(1) End If 'Call PartRunner(oOcc.Definition.Document, aDoc) End If Next End Sub
But the thing is that when i have a suppressed part it gives me an error. Is it possible to tell the ilogic that when it has a supressed part it also has to change the name?
@J-Camper @Anonymous
Hello,
I managed to make this code:
Sub Main If ThisApplication.ActiveDocumentType <> kAssemblyDocumentObject Then MessageBox.Show("This rule is designed to only work in assembly documents.", "Wrong Document Type") : Exit Sub Dim parentDoc As AssemblyDocument = ThisApplication.ActiveDocument 'Do anything unique to main assembly Call AssemblyRunner(parentDoc) End Sub Sub AssemblyRunner(aDoc As AssemblyDocument) 'Do things to the assembly file if any 'MessageBox.Show(aDoc.DisplayName, "Assembly:") 'Start Looping For Each oOcc As ComponentOccurrence In aDoc.ComponentDefinition.Occurrences If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Dim GetOccName As String = oOcc.Name If GetOccName.Contains(":") Then Dim words As String() = GetOccName.Split(":") oEerst = words(0) oTweede = words(1) 'Dim CurFileName As String 'get the selected item document occurrence name doc = oOcc.Definition.Document 'get the path and file name of the selected item CurFileName = doc.FullFileName 'defines backslash as the subdirectory separator Dim strCharSep As String = System.IO.Path.DirectorySeparatorChar 'find the postion of the last backslash in the path FNamePos = InStrRev(CurFileName, "\", -1) 'get the file name with the file extension Name = Right(CurFileName, Len(CurFileName) - FNamePos) 'get the file name (without extension) ShortName = Left(Name, Len(Name) - 4) 'get the path of the folder containing the file Folder_Location = Left(CurFileName, Len(CurFileName) - Len(Name)) oOcc.Name = ShortName & ":" & words(1) End If Call AssemblyRunner(oOcc.Definition.Document) Else If oOcc.DefinitionDocumentType = kPartDocumentObject Dim GetOccName As String = oOcc.Name If GetOccName.Contains(":") Then Dim words As String() = GetOccName.Split(":") oEerst = words(0) oTweede = words(1) 'Dim CurFileName As String 'get the selected item document occurrence name doc = oOcc.Definition.Document 'get the path and file name of the selected item CurFileName = doc.FullFileName 'defines backslash as the subdirectory separator Dim strCharSep As String = System.IO.Path.DirectorySeparatorChar 'find the postion of the last backslash in the path FNamePos = InStrRev(CurFileName, "\", -1) 'get the file name with the file extension Name = Right(CurFileName, Len(CurFileName) - FNamePos) 'get the file name (without extension) ShortName = Left(Name, Len(Name) - 4) 'get the path of the folder containing the file Folder_Location = Left(CurFileName, Len(CurFileName) - Len(Name)) oOcc.Name = ShortName & ":" & words(1) End If 'Call PartRunner(oOcc.Definition.Document, aDoc) End If Next End Sub
But the thing is that when i have a suppressed part it gives me an error. Is it possible to tell the ilogic that when it has a supressed part it also has to change the name?
I mean the easiest thing to do is switch you level of detail to Master before running, so all parts are temporarily un-suppressed. Try this:
Sub Main
If ThisApplication.ActiveDocumentType <> kAssemblyDocumentObject Then MessageBox.Show("This rule is designed to only work in assembly documents.", "Wrong Document Type") : Exit Sub
Dim parentDoc As AssemblyDocument = ThisApplication.ActiveDocument
'Save current LOD
Dim currentLOD As LevelOfDetailRepresentation = parentDoc.ComponentDefinition.RepresentationsManager.ActiveLevelOfDetailRepresentation
'Activate Master
parentDoc.ComponentDefinition.RepresentationsManager.LevelOfDetailRepresentations.Item(1).Activate
'Call Subroutine
Call AssemblyRunner(parentDoc)
'Re-activate initial LOD
currentLOD.Activate
End Sub
Sub AssemblyRunner(aDoc As AssemblyDocument)
'Do things to the assembly file if any
'MessageBox.Show(aDoc.DisplayName, "Assembly:")
'Start Looping
For Each oOcc As ComponentOccurrence In aDoc.ComponentDefinition.Occurrences
Dim GetOccName As String = oOcc.Name
'Only changing names if the name still has a ":"
If GetOccName.Contains(":") Then
Dim words As String() = GetOccName.Split(":")
oEerst = words(0)
oTweede = words(1)
'get the selected item document occurrence name
doc = oOcc.Definition.Document
'get the file name (without extension)
ShortName = System.IO.Path.GetFileNameWithoutExtension(doc.FullFileName)
'get the path of the folder containing the file
Folder_Location = System.IO.Path.GetDirectoryName(doc.FullFileName) & "/"
'Set Name
oOcc.Name = ShortName & ":" & words(1)
End If
If oOcc.DefinitionDocumentType = kAssemblyDocumentObject
'Call for Parts within subassembly
Call AssemblyRunner(oOcc.Definition.Document)
Else If oOcc.DefinitionDocumentType = kPartDocumentObject
End If
Next
End Sub
I saw you were using System.IO.Path to get the separator character, but there are other methods in that System Object which can straight give you what you were manually collecting, so I added those changes. I also consolidated things a bit. you have the same process for all occurrences except for assemblies you run the Assembly sub, So I put the name change first and an If statement to catch Assemblies. If you don't want to use my consolidation, just use the changes in the Main Sub.
Let me know if you have any questions or if it is not working as intended.
I mean the easiest thing to do is switch you level of detail to Master before running, so all parts are temporarily un-suppressed. Try this:
Sub Main
If ThisApplication.ActiveDocumentType <> kAssemblyDocumentObject Then MessageBox.Show("This rule is designed to only work in assembly documents.", "Wrong Document Type") : Exit Sub
Dim parentDoc As AssemblyDocument = ThisApplication.ActiveDocument
'Save current LOD
Dim currentLOD As LevelOfDetailRepresentation = parentDoc.ComponentDefinition.RepresentationsManager.ActiveLevelOfDetailRepresentation
'Activate Master
parentDoc.ComponentDefinition.RepresentationsManager.LevelOfDetailRepresentations.Item(1).Activate
'Call Subroutine
Call AssemblyRunner(parentDoc)
'Re-activate initial LOD
currentLOD.Activate
End Sub
Sub AssemblyRunner(aDoc As AssemblyDocument)
'Do things to the assembly file if any
'MessageBox.Show(aDoc.DisplayName, "Assembly:")
'Start Looping
For Each oOcc As ComponentOccurrence In aDoc.ComponentDefinition.Occurrences
Dim GetOccName As String = oOcc.Name
'Only changing names if the name still has a ":"
If GetOccName.Contains(":") Then
Dim words As String() = GetOccName.Split(":")
oEerst = words(0)
oTweede = words(1)
'get the selected item document occurrence name
doc = oOcc.Definition.Document
'get the file name (without extension)
ShortName = System.IO.Path.GetFileNameWithoutExtension(doc.FullFileName)
'get the path of the folder containing the file
Folder_Location = System.IO.Path.GetDirectoryName(doc.FullFileName) & "/"
'Set Name
oOcc.Name = ShortName & ":" & words(1)
End If
If oOcc.DefinitionDocumentType = kAssemblyDocumentObject
'Call for Parts within subassembly
Call AssemblyRunner(oOcc.Definition.Document)
Else If oOcc.DefinitionDocumentType = kPartDocumentObject
End If
Next
End Sub
I saw you were using System.IO.Path to get the separator character, but there are other methods in that System Object which can straight give you what you were manually collecting, so I added those changes. I also consolidated things a bit. you have the same process for all occurrences except for assemblies you run the Assembly sub, So I put the name change first and an If statement to catch Assemblies. If you don't want to use my consolidation, just use the changes in the Main Sub.
Let me know if you have any questions or if it is not working as intended.
It should function just like you had before except the Main Sub is switching to Master LOD to run everything and then returning to the LOD @ run time afterwards.
Now based on your inner If Statement, which I didn't change, you are only changing Occurrence names which have ":" still in the name, so if an occurrence name is overwritten without ":" it will skip renaming that Occurrence.
It should function just like you had before except the Main Sub is switching to Master LOD to run everything and then returning to the LOD @ run time afterwards.
Now based on your inner If Statement, which I didn't change, you are only changing Occurrence names which have ":" still in the name, so if an occurrence name is overwritten without ":" it will skip renaming that Occurrence.
Can't find what you're looking for? Ask the community or share your knowledge.