Here is an iLogic partial solution to sorting sketch blocks . The only drawback is that it will not sort sketch blocks that are depended on each other.
'[Concept:
'Before running this rule, ensure you test on a sample document and also back up your template.
'This rule is to be run from an internal rule or external rule with the template part document containing the sketch blocks active.
'It will create a list Of sketch blocks and sort the list
'Then add the Sketch block to a new part file in alphabetical order.
'The rule will skip sketch blocks that are depended on each other, these will need to be reordered manually.
'Helpful Starting link
'https://forums.autodesk.com/t5/Inventor-ilogic-api-vba-forum/ilogic-copy-blocks-part-To-part/td-p/10008199
']
'[Start Of Rule
'Document to copy from
Dim FromDoc As PartDocument
FromDoc = ThisDoc.Document
'Create new document
Dim oNewDoc As PartDocument
ToDoc = ThisApplication.Documents.Add(kPartDocumentObject, "", True)'Replace "" with template fullfileName if specific template is needed
Dim BlockNames As New ArrayList
Dim BlockName As String
'Loop through all the Blocks in the Template
For Each oFromBlock As SketchBlockDefinition In FromDoc.ComponentDefinition.SketchBlockDefinitions
'Get sketch block by name
BlockName = oFromBlock.Name
'Add block name to a list
BlockNames.Add(BlockName)
Next
'Display block names
d0 = InputListBox("Prompt", BlockNames, d0, Title := "Before Sort", ListName := "Block List")
'Sort the list of names
BlockNames.Sort()
'Display block names
d0 = InputListBox("Prompt", BlockNames, d0, Title := "After Sort", ListName := "Block List")
'Loop through sketch block names
For Each BlockName In BlockNames
'Loop through Sketch Block Collection
For Each oFromBlock As SketchBlockDefinition In FromDoc.ComponentDefinition.SketchBlockDefinitions
'Match the list to the block definition name
If BlockName = oFromBlock.Name Then
oFromBlock.CopyTo(ToDoc)
End If
Next
Next
'Loop through the blocks sorted and delete any that were added twice due to being dependent on other blocks.
For Each oToBlock As SketchBlockDefinition In ToDoc.ComponentDefinition.SketchBlockDefinitions
'Match the list to the block definition name
If Not BlockNames.Contains(oToBlock.Name)Then
oToBlock.Delete
'MessageBox.Show(oToBlock.Name, "Title")
End If
Next
MessageBox.Show("Sort all done!", "Champion")
']
'End Of Rule
Hopefully that will help anyone looking to sort blocks and save some time.
If this solved a problem, please click (accept) as solution.
Or if this helped you, please, click (like)
Regards
Alan