question

Nicolas Mbz avatar image
0 Likes"
Nicolas Mbz asked Nicolas Mbz commented

How to browse child groups and their content ?

Hello,

I have 6 shapes. 2 shapes in Group1, 3 shapes in Group2 and 1 shape not in a group.

These 2 groups and the shape are children of the group "All".

I want to execute an action (for example change the color) on each of the objects present in the parent group.


1668014949189.png



Maybe the idea is detecting that the element[i] in the parent group is a group, then going inside the element[i] then brows again. But, don't know how to do it and make a clean loop. Help? Thanks in advance


Groups.fsm

FlexSim 22.2.2
groupsloopparent
1668014949189.png (209.5 KiB)
groups.fsm (84.5 KiB)
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
1 Like"
Matthew Gillespie answered Nicolas Mbz commented

The easiest way is to use the Group.toFlatArray() method:

Array all = Group("All").toFlatArray();

for (int i = 1; i <= all.length; i++)
    all[i].color = Color.random();
· 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.

Nicolas Mbz avatar image Nicolas Mbz commented ·
Indeed, very simple, thank you very much !
0 Likes 0 ·