MemberIds of group returns in different order

MemberIds of group returns in different order

Joris.vd.Meulen
Collaborator Collaborator
517 Views
4 Replies
Message 1 of 5

MemberIds of group returns in different order

Joris.vd.Meulen
Collaborator
Collaborator

Hi guys,

 

Yesterday I noticed something strange, at first I thought it was a dynamo custom node thing, but I did some testing yesterday evening and I think that's not the case.  Hence me posting here, to consult your expertise.

 

So, what's the subject?

I'm obtaining all members of a group, nothing strange here. But I thought the order in which this return is given would always be the same, which to my surprise isn't.

So if I test a group, get those members, list[1] would be a door. Checking the same grouptype (no excluded etcetc) returns list[1] wall. 

Doing this on a large scale projects returns the same scattered results. 

 

So two questions I guess:

1. how do I ensure that the order is always the same?

2. how do I prevent this from happening?

3. (or how can I get an element in the group that is always the same for all the other groups I check: example: I want 'door' as result for each group; and if there are more doors, the first in the list for example (so I can't filter on 'door' etc))

 

All this typing is a bit blurry obviously so check this screencast, which shows python but the coding etc is all there, nothing to fancy. It does address a custom node but that part can be ignored (the issue is already narrowed down).

BUT it does show the different list order returns. pfff I'm puzzled.

 

 

love python coding
0 Likes
518 Views
4 Replies
Replies (4)
Message 2 of 5

Joris.vd.Meulen
Collaborator
Collaborator

Pfff testing, testing trying to recreate a changed-order-group.

  • changing parameters of an element in group: no impact
  • exchange of groups: no impact
  • exchange of elements in group: no impact
  • adding a new element to group is always at the end of the list

 

Finally I figured it out: exclude members.
So excluding a member of a group and “restore all excluded” afterwards adds those members to the end of the groupmemberlist.

 

So question 2 is answered, any thoughts on question 1 & 3?

 

1. how do I ensure that the order is always the same?

2. how do I prevent this from happening?

3. (or how can I get an element in the group that is always the same for all the other groups I check: example: I want 'door' as result for each group; and if there are more doors, the first in the list for example (so I can't filter on 'door' etc))

love python coding
0 Likes
Message 3 of 5

jeremytammik
Autodesk
Autodesk

Dear Joris,

 

Thank you for your query and update.

 

I assume you are referring to the return value of the Group.GetMemberIds method:

 

http://www.revitapidocs.com/2018/42a745b8-dc2e-ef06-0ad3-7e4c775eea9d.htm

 

The documentation says about the return value:

 

An ordered list of the members within the group. The order of this list can be used to match members between other instances of the group.

 

I would therefore indeed expect the order to be the same every time, just like you say.

 

Your solution to item 2 makes total sense and explains the mix-up you initially observed.

 

Regarding items 1 and 3, I see a very simple solution to achieve what you are asking for regardless of the order provided by the Revit API:

 

Simply order the list yourself by element id.

 

Would that not enable you to fulfil all the requirements you list?

 

I hope this helps.

 

Best regards,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 4 of 5

Joris.vd.Meulen
Collaborator
Collaborator

Hi @jeremytammik,

 

Thanks for your reply. 

Without having tested this (I will after doing my current project), how will ordering the list by id won't be of any help?

The excluded members will get a new ID after being restored.

 

So comparing two groups will return different list orders (even if I would order them by ID).

  • 1 which has no excluded members
    • familyinstance A, id 100000
    • wall, id 100001
    • wall, id 100002
    • familyinstance B, id 100003
  • 2 which had excluded members
    • wall, id 100001
    • wall, id 100002
    • familyinstance B, id 100003
    • familyinstance A, id 100004

Again, untested, will check tonight.

 

 

love python coding
0 Likes
Message 5 of 5

Joris.vd.Meulen
Collaborator
Collaborator

Order of the elements is indeed scrambled after restoring excluded members. (excluded members get a new ID and are added to the end of a list). Ordering is therefor of no use (to my opinion).

 

Would 'solving' this be to

- get an original group,

- check a certain item "A" and get the index value of it (INDEX)

("A" can occur multiple times)

- remember the last item in group "ENDITEM"

 

Get the next group

- get item at index INDEX and check if the ID is the same

- if not: get the first item "A" after "ENDITEM"

 

Your thoughts?

 

love python coding
0 Likes