Determine (Get) Parts List "Auto Sort on Update" status

Determine (Get) Parts List "Auto Sort on Update" status

DRoam
Mentor Mentor
736 Views
5 Replies
Message 1 of 6

Determine (Get) Parts List "Auto Sort on Update" status

DRoam
Mentor
Mentor

In Inventor 2018 we got the Sort2 method for Parts Lists that lets us set the "AutoSortOnUpdate" status.

 

Is there any way to "Get" the AutoSortOnUpdate status for a Parts List?

 

I'm iterating through all of the Parts Lists in a drawing and setting them to sorted, but the performance is very slow because it runs Sort2 even for Parts Lists that are already sorted. I'd like to only run the Sort2 method if AutoSortOnUpdate is currently off.

737 Views
5 Replies
Replies (5)
Message 2 of 6

JaneFan
Autodesk
Autodesk

Hi @DRoam , 

 

Sorry to say that AutoSortOnUpdate status property for PartsList is not exposed yet. We have to find other ways to work it around for now. How about adding an attribute for those partslists which run into Sort2() method with AutoSortOnUpdate being specified to true, and skip such partslists in the loop?




Jane Fan
Inventor/Fusion QA Engineer
0 Likes
Message 3 of 6

DRoam
Mentor
Mentor

@JaneFan wrote:

How about adding an attribute for those partslists which run into Sort2() method with AutoSortOnUpdate being specified to true, and skip such partslists in the loop?


I'm not sure what you mean by adding an attribute. How do I do that?

0 Likes
Message 4 of 6

JaneFan
Autodesk
Autodesk

The thing in my mind is like this that the attributeset will be added to the parts list which executed Sort2(), then next time it won't run into the loop to execute Sort2() again. 

Sub main
Dim oPartsList As PartsList 
For Each oPartsList In ThisDrawing.Document.Sheets(1).PartsLists
	If Not HasUpdate(oPartsList) Then 
		'Update the following line as your needs
'		oPartsList.Sort2("Item", True, AutoSortOnUpdate :=True)
		oPartsList.AttributeSets.Add("DoneWithAutoUpdate")
	End If 
Next 
End Sub 

Function HasUpdate(oPartsList As PartsList)
		Dim ret As Boolean = False 
		Dim oAS As AttributeSet 
		For Each oAS In oPartsList.AttributeSets
			If oAS.Name = "DoneWithAutoUpdate" Then 
				ret = True 
				Exit For 
			End If 
		Next 
		Return ret
End Function 

 




Jane Fan
Inventor/Fusion QA Engineer
Message 5 of 6

DRoam
Mentor
Mentor

I had no idea the attribute functionality existed, thanks for showing me that! I'd seen the "AttributeSets" property before but I assumed it was for read-only built-in Inventor attributes of the object. I didn't know I could create my own attributes. This is really useful to know.

 

Unfortunately, it's not ideal for this case because Parts Lists can easily lose auto-sort accidentally, such as when switching Styles or adding columns, and the attribute wouldn't know this. An un-sorted parts list could easily go unnoticed.

 

I think for now I'm going to make the parts list sorting a separate command from the main updater I'm building, so we can run the sort tool before printing a drawing but it won't run every time the main updater is run.

 

I just found this idea asking for API access to the Auto Sort setting, so if anyone else thinks this would be useful please give it a vote as well: API access to auto sort on update in parts list.

0 Likes
Message 6 of 6

dusan.naus.trz
Advisor
Advisor

Hi,

https://forums.autodesk.com/t5/inventor-customization/ilogic-auto-sort-on-update-check-box/td-p/7515042
0 Likes