Message 1 of 11
Auto Folder for Components (FAST) ilogic code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
finally after utilizing snippets of the best code out there I created an auto folder tool that is blazingly fast. I suggest Autodesk implements this as it is so quick.
there are a few issues with it that I hope some beautiful people can help me solve.
Component patterns placed in folders are causing them to go above the model states folder which I didn't even think was possible.
also if there was a way without sacrificing speed to only place components if there is more than one in the folder. currently it places all unique ones into a folder.
Dim oDoc1 As Document
oDoc1 = ThisApplication.ActiveDocument
Dim oTopNode3 As BrowserNode
oTopNode3 = oDoc1.BrowserPanes.ActivePane.TopNode
Dim oNode3 As BrowserNode
For Each oNode3 In oTopNode3.BrowserNodes
oNode3.DoSelect
If oNode3.BrowserNodeDefinition.Label.Contains(":") = True Then
If oNode3.BrowserNodeDefinition.Label.Contains("Model States") = False Then
If oNode3.BrowserNodeDefinition.Label.Contains("Component Pattern") = False Then
oNode3.DoSelect
Try
'define assembly doc
Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
'define assembly Component Definition
Dim oAsmCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
'Dim itemName As ComponentOccurrence
startagain :
SendKeys.SendWait("{ESC}")
AppActivate(ThisApplication.Caption)
c = ThisApplication.ActiveDocument.SelectSet.Item(1)
'c = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllEntitiesFilter, "Select component")
If c Is Nothing Then
Exit Sub
Else
'get the path and file name of the selected item
d = Component.InventorComponent(c.name).Definition.Document.FullFileName
f = IO.Path.GetFileNameWithoutExtension(d)
'MsgBox(f)
'exit sub
End If
'f = InputBox("Input Wildcard of Item you want to put in the folder", "BrowserNodeItem Name", "****")
'sFolder = f
If f = "" Then
Exit Sub
Else If f = "** Item Name**"
MsgBox("please enter item number")
Exit Sub
End If
'get browser pane
'Dim oPane As BrowserPane = oDoc.BrowserPanes.ActivePane
Dim oPane As BrowserPane = oDoc.BrowserPanes("Model")
Dim oTopNode As BrowserNode = oPane.TopNode
'try to get existing folder by name and delete it
'catch error if not found
Dim oFolder As BrowserFolder
Try
oFolder = oPane.TopNode.BrowserFolders.Item(f)
oFolder.Delete
Catch
End Try
Dim oCollection As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
'Iterate through all of the occurrences in the assembly
Dim oOcc As ComponentOccurrence
Dim part As String = "Part"
Dim assembly As String = "Assembly"
For Each oOcc In oAsmCompDef.Occurrences
If oOcc.Name.Contains(f) And Inventor.DocumentTypeEnum.kPartDocumentObject Then
If TypeOf oOcc.Definition Is PartComponentDefinition Then
'get browser node of occurence
Dim oNode As BrowserNode = oPane.GetBrowserNodeFromObject(oOcc)
'add node to collection
oCollection.Add(oNode)
End If
End If
If oOcc.Name.Contains(f) And Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
If TypeOf oOcc.Definition Is AssemblyComponentDefinition Then
'get browser node of occurence
Dim oNode1 As BrowserNode = oPane.GetBrowserNodeFromObject(oOcc)
'add node to collection
oCollection.Add(oNode1)
End If
End If
Next
' recreate folder
'And add collection To folder
Try
oFolder = oPane.AddBrowserFolder(f, oCollection)
Catch
MessageBox.Show("Error", "ilogic")
End Try
oFolder.BrowserNode.DoSelect
GoTo startagain
'SOURCECODE: https://forums.autodesk.com/t5/inventor-forum/ilogic-to-create-browser-node-folder-and-move-all-iparts-and/td-p/9000788
Catch
End Try
End If
End If
End If
Next