Hello Community,
I have encountered an interesting problem and I hope anyone could solve it.
I would like to get the object list in a model with the function ObjOccList.
The function could indeed get all the object back, but every time the the objects returned from the function are in different order. For example I have 3 objects in the model name"A,B,C". When I try to get the object with ObjOccList,
it will return "A,B,C" at the first time and "B,A,C" at the second time.
Is there any variable of this function that I could set to fix the order of the object?
Thank you in advance!
The server doesn't take a list it has somewhere and hand it to you, instead you can imagine it like a bunch of files spread out on a desk (similar to your object occurrences sitting at different x and y coordinates in your model). When you call the method the server just stacks the files on top of each other, grabbing random ones from all over the table, and hands you the complete stack of files. It doesn't care about sorting them at all, all that matters for it is that is as fast as possible.
After you were handed the stack of paper (an array containing the object occurrences), you are the one that is responsible for sorting them. You can do so in two ways (as far as I know).
You can either use an ARIS method, ArisData.sort(...), which allows you to sort by certain criteria:
e.g.
var arrayNowSorted = ArisData.sort(selModel.ObjOccList(), Constants.SORT_X, Context.getSelectedLanguage());
Or you can go the JavaScript way of sorting an array containing objects, with a custom sorting method. This allows you to sort by basically any information of the objects you can somehow access. The Javascript way changes the original array, so assign it to a variable first.
e.g.
var soonToBeSortedArray = selModel.ObjOccList(); soonToBeSortedArray.sort(function(a,b){ return a.X() - b.X() });
For this example I used the X() method from the ObjectOcc class, but as I said earlier, you can use it to sort by anything. E.g. you could use a.ObjDef().Attribute(...).getValue() to get a value from an attribute and sort by that.
As far as I can tell, the ArisData.sort() method also accepts methods as arguments and you could do your custom sorting through that too.