Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic Auto Sort on Update check box

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
nbroughton
1266 Views, 7 Replies

iLogic Auto Sort on Update check box

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.

 

2017-11-03 09_37_29-Sort Parts List.jpg

 

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 

 

7 REPLIES 7
Message 2 of 8
Anonymous
in reply to: nbroughton

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

www.symetri.com

Message 3 of 8
nbroughton
in reply to: Anonymous

@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.

 

Message 4 of 8
Anonymous
in reply to: nbroughton

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

www.symetri.com

Message 5 of 8
nbroughton
in reply to: Anonymous

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

 

Message 6 of 8
Anonymous
in reply to: nbroughton

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

Message 7 of 8
nbroughton
in reply to: Anonymous

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.

Message 8 of 8
j.lisle
in reply to: nbroughton

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.

Post to forums  

Technology Administrators


Autodesk Design & Make Report