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

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

kim_jh
Not applicable
18 Views
2 Replies
Message 1 of 3

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

kim_jh
Not applicable
 
Accepted solutions (1)
19 Views
2 Replies
Replies (2)
Message 2 of 3

Matthew_Gillespie
Autodesk
Autodesk
Accepted solution

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();
}


Matthew Gillespie
FlexSim Software Developer

Message 3 of 3

Brandon_Peterson
Autodesk
Autodesk

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

img src="https://damassets.autodesk.net/content/dam/autodesk/logos/autodesk-logo-primary-rgbblack-small_forum.png" >

Brandon Peterson
Principal Technology Consultant
>