I am new to the ilogic world of Inventor as well as the programming language. I have created a rule that will Sort by "Vendor", "Description", and "Size", "Renumber" and then "Save Item Overrides To BOM". What I would like to be able to do is have some way to check off the "Auto Sort on Update" box (see attached mage) before renumbering the BOM. If anyone knows what I need to type in to get that to happen would be my hero and all my dreams would come true. Any help is greatly appreciated.
This is the script I have so far.
SyntaxEditor Code Snippet
On Error Resume Next Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument Dim oPartsList1 As PartsList Dim oPartsList2 As PartsList Dim oPartsList3 As PartsList Dim oPartsList4 As PartsList oPartsList1 = oDrawDoc.ActiveSheet.PartsLists.Item(1) oPartsList1.Sort("VENDOR",1,"DESCRIPTION",1,"SIZE",1) oPartsList1.Renumber oPartsList1.SaveItemOverridesToBOM oPartsList2 = oDrawDoc.ActiveSheet.PartsLists.Item(2) oPartsList2.Sort("VENDOR",1,"DESCRIPTION",1,"SIZE",1) oPartsList2.Renumber oPartsList2.SaveItemOverridesToBOM oPartsList3 = oDrawDoc.ActiveSheet.PartsLists.Item(3) oPartsList3.Sort("VENDOR",1,"DESCRIPTION",1,"SIZE",1) oPartsList3.Renumber oPartsList3.SaveItemOverridesToBOM oPartsList4 = oDrawDoc.ActiveSheet.PartsLists.Item(4) oPartsList4.Sort("VENDOR",1,"DESCRIPTION",1,"SIZE",1) oPartsList4.Renumber oPartsList4.SaveItemOverridesToBOM
Solved! Go to Solution.
Solved by nbroughton. Go to Solution.
Hello @nbroughton
I think you are almost there.
When I look in the API help for the Inventor.Partslist object I see two Sort methods, the one you have used and a Sort2 with two extra arguments:
PartsList.Sort2( PrimaryColumnTitle As String, _
[PrimaryColumnAscending] As Boolean, _
[SecondaryColumnTitle] As String, _
[SecondaryColumnAscending] As Boolean, _
[TertiaryColumnTitle] As String, _
[TertiaryColumnAscending] As Boolean, _
[SortByString] As Boolean, _
[AutoSortOnUpdate] As Boolean )
I think the last argument, AutoSortOnUpdate may be what you are looking for?
Regards,
Jens Bejer Pedersen
Developer, Symetri A/S
@Anonymous
I tried adding this to the code oPartsList1.Sort2(AutoSortOnUpdate,1) whenever I run the script now Inventor all together crashes popping up the error report screen.
You mentioned looking in the API help, could you send me a link to that? Thanks for the quick response.
Hello @nbroughton
The Inventor 2018 API Help is here:
http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-6FD7AA08-1E43-43FC-971B-5F20E56C8846
And the page for the PartsList.Sort2 method is here:
http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-68E803C6-7E76-4415-BD38-A6311636BA51
You should replace the oPartsList1.Sort(<your current parameters>) with oPartsList1.Sort2(<your current parameters>, True, False)
For example, in your original code you have:
oPartsList1.Sort("VENDOR",1,"DESCRIPTION",1,"SIZE",1)
Replace that with:
oPartsList1.Sort2("VENDOR",1,"DESCRIPTION",1,"SIZE",1, True, False)
The last argument is the AutoSortOnUpdate, and True means do the Auto update false means don't do the auto update.
Regards,
Jens Bejer Pedersen
Developer, Symetri A/S
The below code works great, it isn't exactly as you said but what you said helped me figure it out, thank you much.
SyntaxEditor Code Snippet
On Error Resume Next Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument Dim oPartsList1 As PartsList Dim oPartsList2 As PartsList Dim oPartsList3 As PartsList Dim oPartsList4 As PartsList oPartsList1 = oDrawDoc.ActiveSheet.PartsLists.Item(1) oPartsList1.Sort2("VENDOR",1,"DESCRIPTION",1,"SIZE",1,AutoSortOnUpdate,True) oPartsList1.Renumber oPartsList1.SaveItemOverridesToBOM oPartsList2 = oDrawDoc.ActiveSheet.PartsLists.Item(2) oPartsList2.Sort2("VENDOR",1,"DESCRIPTION",1,"SIZE",1,AutoSortOnUpdate,True) oPartsList2.Renumber oPartsList2.SaveItemOverridesToBOM oPartsList3 = oDrawDoc.ActiveSheet.PartsLists.Item(3) oPartsList3.Sort2("VENDOR",1,"DESCRIPTION",1,"SIZE",1,AutoSortOnUpdate,True) oPartsList3.Renumber oPartsList3.SaveItemOverridesToBOM oPartsList4 = oDrawDoc.ActiveSheet.PartsLists.Item(4) oPartsList4.Sort2("VENDOR",1,"DESCRIPTION",1,"SIZE",1,AutoSortOnUpdate,True) oPartsList4.Renumber oPartsList4.SaveItemOverridesToBOM
Hello @nbroughton
Good that it worked.
I think i may have misunderstood your original post.
When you wrote >>check off the "Auto Sort on Update" box<< I read this as unchecking the box, and this should mean using False for the last argument for Sort2, but now I think you intended to check the box, and yes then you will need True for the last argument.
The second to last argument to Sort2 actually control if the sort is numerical or text, the default is True for text and in you latest code I can't see what you have set for value in your AutoSortOnUpdate variable, and if you haven't set the variable then Sort2 probably uses the default.
Regards,
Jens Bejer Pedersen
Developer, Symetri A/S
www.symetri.com
The True at the end of the argument sets the check box to being checked, if it were false the box would be unchecked.
If I'm not mistaken by omitting the last ",True" it defaults to text.
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 oPartsList1 = oDrawDoc.ActiveSheet.PartsLists.Item(1) oPartsList1.Sort("ITEM",1,AutoSortOnUpdate,True) oPartsList1.SaveItemOverridesToBOM End If Next
Can't find what you're looking for? Ask the community or share your knowledge.