I have got some ilogic code that i have patched together to sort my parts list in inventor which works great but it will not update all sheets at the same time as when we design we have multiple sheets with parts list on and the odd one without.
Can anyone help me to add to this code to update all sheets partlists and also recognise that some sheets will not have partslists on so this will need to skip.
below is code that is used to sort
Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 4558 StartFragment: 314 EndFragment: 4526 StartSelection: 314 EndSelection: 314
SyntaxEditor Code Snippet
Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 4558 StartFragment: 314 EndFragment: 4526 StartSelection: 314 EndSelection: 314
SyntaxEditor Code Snippet
'parts list sort Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument Dim oPartsList1 As PartsList oPartsList1 = oDrawDoc.ActiveSheet.PartsLists.Item(1) oPartsList1.Sort("MATERIAL", 0, "L", 0, "W", 0) 'oPartsList1.Sort("ITEM", 1, "DESCRIPTION", 1, "QTY", 1) oPartsList1.Renumber oPartsList1.SaveItemOverridesToBOM
iLogicVb.UpdateWhenDone = True ThisApplication.ActiveView.Fit
Solved! Go to Solution.
Solved by dclunie. Go to Solution.
Solved by coreyparks. Go to Solution.
Hi,
you're using DrawingDocument.ActiveSheet and its PartLists property (Item(1)) - this means you're sorting just the first partlist on the active sheet.
In order to do a sort on all partlists on all sheets you should iterate over DrawingDocument.Sheets property and then Sheet.PartLists property on each sheet. That means you should have 2 nested "for" loops.
Let me know if you need more advice. You can write me an email at martin (dot) bernat (at) autodesk (dot) com.
Thanks for your question.
Martin Bernat
Autodesk
Hi Martin
Thanks for the response but as I have very little knowledge of manipulating code I am to be honest struggling to achieve as explained in reply.
Would it be possible to show me some pasted code with the appropriate modified code so I can better understand where I'm going wrong.
Sorry to be cheeky but I am not experienced enough .
Regards
Dave
'parts list sort Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument Dim oPartsList1 As PartsList oPartsList1 = oDrawDoc.ActiveSheet.PartsLists.Item(1) oPartsList1.Sort("PART NUMBER", 1, "DESCRIPTION", 1, "QTY", 1) 'oPartsList1.Sort("ITEM", 1, "DESCRIPTION", 1, "QTY", 1) oPartsList1.Renumber oPartsList1.SaveItemOverridesToBOM iLogicVb.UpdateWhenDone = True ThisApplication.ActiveView.Fit
Try this code, it works for me anyway. Currently only sorts by part number but does so on every sheet and skips sheets without a partlist on them. Hope this helps.
On Error Resume Next
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
Dim Sheet As Inventor.Sheet
Dim Cursheet As String
Cursheet = oDrawDoc.ActiveSheet.Name
For Each oSheet In oDrawDoc.Sheets
oSheet.Activate
Dim oPartsList As PartsList
oPartsList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
If Not oPartsList Is Nothing Then
Resume Next
Call oPartsList.Sort("ITEM")
End If
Next
Many thanks for the code it works great i have added some other areas to be sorted in vb and added additional lines to take you back to sheet 1 and update active view on all sheets .
On Error Resume Next Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument Dim Sheet As Inventor.Sheet Dim Cursheet As String Cursheet = oDrawDoc.ActiveSheet.Name For Each oSheet In oDrawDoc.Sheets oSheet.Activate Dim oPartsList As PartsList oPartsList = oDrawDoc.ActiveSheet.PartsLists.Item(1) If Not oPartsList Is Nothing Then Resume Next 'Call oPartsList.Sort("ITEM") Call oPartsList.Sort("PART NUMBER", 1, "DESCRIPTION", 1, "QTY", 1) iLogicVb.UpdateWhenDone = True ActiveSheet = ThisDrawing.Sheet("Sheet:1") ThisApplication.ActiveView.Fit End If Next