question

Chidambaram avatar image
0 Likes"
Chidambaram asked Logan Gold commented

Rearrange objects or Rename objects within group

Hi I like to know is there a simple way to rearrange or rename object within group?

For instance Group 1 has 5 objects (Queue 1 to 5) that are attached to a plane. When i copy and paste the plane , the objects are adding to the same group ( but not in chronological order like Queue1,queue2,.. ). The order is collapsed (refer plane 3 objects). Refer attached model for reference.


(1) Either i like to rearrange objects within the same group or

(2) I like to duplicate the parent group ( Group1 ) and duplicate the group named (Group1) to Group 2 and then rename the objects within the group . For instance : Group 1 will have > Plane1/Queue1 , in Group 2 should have > Plane2/Queue1 . I need to change the object name instead of Plane1 to plane2 with scripts. Rearrange within group.fsm


1736987175030.png

FlexSim 24.2.2
groupobjectsrearrange
· 3
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

Felix Möhlmann avatar image
0 Likes"
Felix Möhlmann answered

1) You could just run a sorting algorithm over the group members, sorting them by their tree rank (and that of their parent node).

  1. // Bubblesort
  2. treenode group = Group("Group1");
  3. Object obj1;
  4. Object obj2;
  5. for(int i = 2; i <= group.subnodes.length; i++)
  6. {
  7.     for(int j = group.subnodes.length; j > i; j--)
  8.     {
  9.         obj1 = ownerobject(group.subnodes[j].value);
  10.         obj2 = ownerobject(group.subnodes[j-1].value);
  11.         if(obj1.rank + obj1.up.rank*100 < obj2.rank + obj2.up.rank*100)
  12.         {
  13.             group.subnodes[j].rank = j-1;
  14.         }
  15.     }
  16. }

2) Creating a copy of the plane and adding its subnodes to a new group is also possible.

  1. Object basePlane = Model.find("Plane1");
  2. int index = 2;
  3. Group newGroup = Tools.create("Group");
  4. newGroup.name = "Group" + index;
  5. Object newPlane = createcopy(basePlane, basePlane.up);
  6. newPlane.name = "Plane" + index;
  7. for(int i = 1; i <= newPlane.subnodes.length; i++)
  8. {
  9.     newGroup.addMember(newPlane.subnodes[i]);
  10. }
5 |100000

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