Is it Possible to Get Current PartsList Sort Configuration?

Is it Possible to Get Current PartsList Sort Configuration?

SometimesInventorMakesMeAngry
Advocate Advocate
528 Views
5 Replies
Message 1 of 6

Is it Possible to Get Current PartsList Sort Configuration?

SometimesInventorMakesMeAngry
Advocate
Advocate

I have an add-in that does a few things on documents before saving. On drawings, I collapse the browser tree & fit the view. This takes about a quarter of a second.

 

I'd like to also sort the parts list(s), but retrieving them and doing a Sort2() on them now makes saving take more than 1.5 seconds on a drawing with a single PartsList, which is annoying if you're saving frequently. I'd like to do something like (pseudo code)

if(!partsList.IsSorted)
{
    partsList.Sort2(...);
}

 so that it doesn't actually sort every time -- only when necessary.

 

I thought about using drawing.ReferencedDocuments to get the model and getting the ReasonsForChange from part.DocumentEvents, but it seems messy and Inventor.CommandTypesEnum.kShapeEditCmdType doesn't seem specific enough. Any suggestions are appreciated.

0 Likes
Accepted solutions (1)
529 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor
Accepted solution

As far as I know, there is not 'IsSorted' property for a PartsList, but you could create something similar for your own use, when you do sort them.  A PartsList object has an AttributeSets property, and you could create one (or more) Attributes in it which you could write something to when you sort it, that will let you know in the future, that this PartsList has been sorted (and possibly how it was sorted in another attribute).

Short of that, you could create a Function that attempts to inspect the contents of the PartsList cells, to see if they are in the expected order, and return a Boolean, but that may just add to the time, rather than reduce it.

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 6

SometimesInventorMakesMeAngry
Advocate
Advocate
I thought about doing something like this, but the problem is that if a component is placed or removed in the assembly, the BOM item numbering and sorting breaks. So I would need to subscribe to some event that is raised when this happens, but I don't think there is something like this.

At least I know it's not possible. Thanks!
0 Likes
Message 4 of 6

There might be an event or two you could create a custom 'event handler' for, if you think it would be worth the trouble.

Under the AssemblyEvents object, there are a couple of events that sound about right.  The OnNewOccurrence event, and the OnOccurrenceChange event.  I have created some custom event handlers before, but did so using iLogic (not within an add-in), and haven't tried dealing with these specific events before, so I don't have an immediately useful code example for you to start from right now.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 6

SometimesInventorMakesMeAngry
Advocate
Advocate
That's alright. I've made event handlers before, so I should be able to figure that part out.

It does seem like it would be messy, though. The idea was to sort the parts list on drawing save. But I would have to subscribe to the assembly's OnOccurrenceChange event. I'm thinking I would have to create a custom assembly class, create a new instance for every open assembly, create a public bool property OccurrencesChanged and update it when a component is placed/removed (true) and after I sort(false). But I don't know if these instances will be kept in memory while Inventor is open.

Please let me know if you have a better solution.
0 Likes
Message 6 of 6

SometimesInventorMakesMeAngry
Advocate
Advocate

Upon further thought, I don't need to re-sort every time the assembly BOM changes because I always sort the assy's BOM and then sort the parts list by item number. But I can enable "Auto Sort On Update" in the parts list, so I would only have to do this once and set an attribute like you said IsSorted = true.

The only problem is if someone else touches it and decides to disable that option in the parts list, the add-in will think the option is still enabled and then the parts list will be messed up if the BOM changes.

0 Likes