question

asb.p avatar image
0 Likes"
asb.p asked Matthew Gillespie answered

Error while adding members to a group from a dropscript

Hello,

I am trying to write this command on the dropscript of my custom library. Code is throwing an exception

exception: FlexScript exception: MODEL:/Tools/UserCommands/DropScriptStation/code

treenode newProcessor = dropuserlibraryobject(node("..>AssemblyStation", c), ontoObj, x, y, z, ontoView);
treenode GroupNode =model().find("Tools/Groups");
treenode ALL_AssemblyStations = GroupNode.find("AllStations");
if(!ALL_AssemblyStations)
{
	ALL_AssemblyStations = GroupNode.subnodes.assert("AllStations");
}
Group AllStations = Group("AllStations");
AllStations.addMember(newProcessor);

return newProcessor;

When I debug the code I didn't found any Issues. Can anyone let me know why this issue is happening? Is it because the object is not added to the model tree yet?

Thanks,

Praneeth.

FlexSim 18.0.5
exception errorgroupsuser librarylibrarydropscript
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
2 Likes"
Matthew Gillespie answered

The Group.addMember method is throwing an exception because AllStations isn't a Group. You can't just create a new Group by adding a subnode in the Groups folder. A Group is a specific type of object that you need to create an instance of. Take a look at this screenshot:

Group1 was a Group that I made through the add button in the toolbox. AllStations is the subnode that your code is adding. Notice that Group1 has Object data, is an instance of the Group class, and has a bunch of other subnodes.

You can create a new group using this application command:

Group group = applicationcommand("createnewgroup");

Here's how I would update your code:

treenode newProcessor = dropuserlibraryobject(node("..>AssemblyStation", c), ontoObj, x, y, z, ontoView);

string groupName = "AllStations";
Group group = Group(groupName);
if(!group) {
	group = applicationcommand("createnewgroup");
	group.name = groupName;
}

group.addMember(newProcessor);

return newProcessor;

groups.png (5.3 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.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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