question

Kim Jh avatar image
3 Likes"
Kim Jh asked Brandon Peterson edited

How to list(write) all objects of a group in order with FlexScript?

flexscriptcommandsgroupgroupmembergroupnummembers
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Matthew Gillespie avatar image
4 Likes"
Matthew Gillespie answered Brandon Peterson edited

In 16.1 we added some new group commands, two of which are very helpful in this situation:

groupnummembers(groupName) - returns the number of group members

groupmember(groupName, rank) - returns the group member at the specified rank

Using these new commands we can write the following code to loop through the group members:

for(int i = 1; i <= groupnummembers("Group1"); i++) {
	pt(getname(groupmember("Group1", i))); pr();
}
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Brandon Peterson avatar image Brandon Peterson ♦ commented ·

Kim Jh,

Here is an alternative approach if you are using an earlier version than 16.1:

All groups are located in the node "Tools/Groups" in the model. The following code will print the names of all the objects in "Group1" to the output console.

treenode groups = node("/Tools/Groups", model());
treenode mygroup = node("/Group1", groups);
for(int i1 = 1; i1 <= content(mygroup); i1++){
	treenode tempobj = ownerobject(tonode(getnodenum(rank(mygroup, i1))));
	pr(); pt(getname(tempobj));
}

The nodes in the group are couplings to the objects in the group. The code that sets the tempobj variable is the method that I use to get the node that owns the other side of that coupling.

Good Luck,

Brandon

3 Likes 3 ·