I had a customer recently ask me if there was a way to automatically place components in relevant assembly folders, as they try to keep the assembly browser as organized as possible. Unfortunately, there is no out-of-the-box tool that will accomplish this, but thanks to iLogic, it absolutely can be done! This post will walk through one possible approach.
Before we get into things, a special thanks goes out to my colleague, Curtis Waguespack, who really helped me when I was really stuck in a particular portion of my initial code! He is awesome!!!
The first step in the process is to determine how to categorize each component, so that it can eventually be placed into the proper assembly browser folder. I decided to use iProperties, as those are readily accessible, can be included in file templates and can be mapped to Content Center tables. As you can see in the graphic below, I am using a custom iProperty called “Assembly_Folder” to define this value.
Important Note: It is critically important to ensure that the iProperty name is IDENTICAL in every component, otherwise the iLogic code will NOT work.
Sample component with the Custom iProperty “Assembly_Folder”
After ensuring that the components have the required Custom iProperty, simply build or open an assembly that contains the components. To verify the desired functionality, I have made several copies of the components in this assembly.
Sample assembly with multiple component copies
The final step is to implement some iLogic code that will determine which folders need to be created, create those folders, and then place the components into the corresponding folder, all of which is based on the components’ Custom iProperty values. I am including the text of the rule below, as well as a YouTube video link that demonstrates the functionality in real time, but I want to list some important items to consider.
Execute the iLogic rule
The components have now been reorganized into assembly folders that were generated “on-the-fly”
As you can see, the iLogic rule will organize the components automatically into the folders designated by and generated from the components’ Custom iProperties. This gives the end users maximum flexibility to organize components as desired, without having to create the folders ahead of time. I hope you find this tip helpful and please a let me know if you have any questions or comments. Hope all is well and happy blogging! - Pete Strycharske
Link to YouTube Video:
iLogic Code:
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
If ThisApplication.ActiveDocument.DocumentType <> _
DocumentTypeEnum.kAssemblyDocumentObject Then Return
Dim oDef As ComponentDefinition
oDef = oDoc.ComponentDefinition
'Define the Model Browser pane to ensure folders are created in the proper location
Dim oPane As BrowserPane
oPane = oDoc.BrowserPanes.Item("Model")
Dim oTopNode As BrowserNode
oTopNode = oPane.TopNode
Dim oTargetNode As BrowserNode
Dim oFolder As BrowserFolder
oTargetNode = oTopNode
Dim oList As New ArrayList
'create a list of the folders to make based on the custom iProperties in each component
'This will allow folders to be created on the fly
For Each oOcc In oDef.Occurrences
Try
sFolder = iProperties.Value(oOcc.name, "Custom", "Assembly_Folder")
If oList.Contains(sFolder) = False Then
oList.Add(sFolder)
End If
Catch 'error when iprop doesn't exist
End Try
Next
'Sorts the list alphabetically
oList.Sort
'compare list to existing folders
For Each oFolder In oTargetNode.BrowserFolders
If oList.Contains(oFolder.Name) Then
'remove from list if it exists
oList.Remove(oFolder.Name)
End If
Next
'create folders that don't exist
If oList.Count > 0
For Each sFolder In oList
oFolder = oPane.AddBrowserFolder(sFolder)
oFolder.AllowReorder = True
oFolder.AllowDelete = True
Next
End If
'Check each folder and populate it with components that have the corresponding custom iProperty value
For Each oFolder In oTargetNode.BrowserFolders
For Each oOcc In oDef.Occurrences
Dim oNode As BrowserNode
oNode = oPane.GetBrowserNodeFromObject(oOcc)
Try
If oFolder.Name = iProperties.Value(oOcc.Name, "Custom", "Assembly_Folder") Then
oFolder.Add(oNode)
'Optional verification message
MessageBox.Show(oOcc.Name & " has been added to the folder: " & oFolder.Name, "Component Added to Folder")
End If
Catch
End Try
Next
Next
Do you use any of these tips and tricks in your daily workflow? Feel free to brag about your success in the comments!
Like what you’ve read? Subscribe to our blog!
Feel free to share on Twitter or Facebook!