- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone,
I'm working with iLogic for a couple of months now. Most problems while learning are quite managable using the forum, but this time I'm really stuck...
I built myself a function, that I'm already using in some rules.
It's going through all components in an assembly, collects the ones containing a certain name in an object list and then puts all components in a folder. To be exact: it checks if a browser folder is there and creates one if not.
This works fine and reliably, but it doesn't work for patterns. I keep failing to also move a pattern into the folder. I can do it manually by drag&drop, so it should work after all. But simply adding the pattern as an object to the list, so it also loops the pattern, doesn't do the trick...
Here's my code:
Sub Main() PartName = "Finger protection" AddToFolder("Fingerplates", PartName) End Sub Function AddToFolder(FolderName As String, PartName As String) ' Add all components and patterns containing the PartName into a list Dim oADoc As AssemblyDocument = ThisDoc.Document Dim oPane As BrowserPane = oADoc.BrowserPanes.Item("Model") Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition Dim oOccs As ComponentOccurrences = oADef.Occurrences Dim oPatterns As OccurrencePatterns = oADef.OccurrencePatterns Dim oItemsToAdd As New List(Of Object) Dim oPFolder As BrowserFolder = Nothing ' Search for all occurrences containing the PartName For Each occ As ComponentOccurrence In oOccs If occ.Name.Contains(PartName) Then oItemsToAdd.Add(occ) Logger.Trace("Occurrence found: " & occ.Name) Else Logger.Trace("No component found") End If Next ' Search for all patterns containing the PartName For Each pattern As OccurrencePattern In oPatterns If pattern.Name.Contains(PartName) Then oItemsToAdd.Add(pattern) Logger.Trace("Occurrence found: " & pattern.Name) Else Logger.Trace("No component found") End If Next ' Add all items from the list to the folder If oItemsToAdd.Count > 0 Then ' Create the folder if it doesn't exist Try oPFolder = oPane.TopNode.BrowserFolders.Item(FolderName) Catch oPFolder = oPane.AddBrowserFolder(FolderName, Nothing) End Try ' Loop through the list and add each item to the folder For Each item In oItemsToAdd Dim oNode As BrowserNode = oPane.GetBrowserNodeFromObject(item) If oNode IsNot Nothing Then Try oPFolder.Add(oNode) Catch Logger.Trace(item.Name) End Try End If Next End If End Function
Hope someone has had something like this already. Thanks in advance!
Solved! Go to Solution.