Creating Group Using Flexscript?

Creating Group Using Flexscript?

rajankur6494
Collaborator Collaborator
676 Views
3 Replies
Message 1 of 4

Creating Group Using Flexscript?

rajankur6494
Collaborator
Collaborator

[ FlexSim 21.1.5 ]

Hi Team,

I am trying to create group using flexscript with custom name. I am using follwing code:

Group newGroup = createinstance(Group, treenode);

It is not working. I feel this syntax is not correct.

Can you help me how to proceed?

Thank you!

Accepted solutions (1)
677 Views
3 Replies
Replies (3)
Message 2 of 4

arunTTT2P
Advisor
Advisor

Hi ,

Group group = Tools.create("Group"); // Create group using the new Tools API
group.name = "xyz"; // Custom name to the group

Furthermore, to add members to the group use

group.addMember();

Regards,

Arun KR

0 Likes
Message 3 of 4

jason_lightfoot_adsk
Autodesk
Autodesk
Accepted solution

For versions 22.1 and earlier (the OP's version is 21) use:

string newgroupname="MyNewGroup";
treenode groups=Model.find("Tools").subnodes.assert("Groups");
treenode group=groups.subnodes[newgroupname];
if (!group) {
    treenode group=createinstance(maintree().find("project/library/Group"),groups);
    group.name=newgroupname;
}

to add members in 17.2 and later versions use the same as Arun's answer:

Group("MyNewGroup").addMember(<objectref>);

For 17 and 17.1 use

groupaddmember(<groupname>,<objectref>)
0 Likes
Message 4 of 4

Jacob_White
Community Manager
Community Manager

Hi @Ankur A3, was one of Arun Kr's or Jason Lightfoot's answers helpful? If so, please click the "Accept" button at the bottom of the one that best answers your question. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.

0 Likes