question

Hai L2 avatar image
0 Likes"
Hai L2 asked Hai L2 commented

Add and removing operator/fix resource from code?

Hi all,

I have a table with a list of operators and a table of equipment. I would like to add those operators and equipment when the model starts or reset. I was able to add objects following an example in this forum, but I couldn't find a way to delete all objects of a specific type.

Is there a recommended way to say delete all operators in the model using code?

Are there better approaches for what I am trying to do? .. adding operator and equipment from a table

Thanks,

Hai

FlexSim 20.2.1
flexsim 20.2.1operators assignment
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

·
Jason Lightfoot avatar image
0 Likes"
Jason Lightfoot answered Hai L2 commented

When you add them to the model you could also add them to a group, and then when you want to destroy them just loop through the group members. Commands for using groups are documented here.

· 4
5 |100000

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

Hai L2 avatar image Hai L2 commented ·

Thanks for the reply. I tried looping over all items in Group("Tools")[i].destroy(); but that didn't seem to work. Am I missing some steps?

0 Likes 0 ·
Brittany Evans avatar image Brittany Evans ♦ Hai L2 commented ·

Hello @Hai L2,

In your code, are you doing a for loop where i is your index that increments each time? If this is the case, once you destroy someone in the group the number of things in the group decreases. This would lead to not everything being removed properly. I would recommend changing the code to Group("Tools")[1].destroy().

If this doesn't help, the I would first check that things are getting added to your group properly. If they are, I would then attach the model so we can take a closer look at what could be going wrong.

1 Like 1 ·
Jason Lightfoot avatar image Jason Lightfoot ♦ Brittany Evans ♦ commented ·

Or my favorite: i--

0 Likes 0 ·
Hai L2 avatar image Hai L2 commented ·

Thank you everyone, Group("Tools")[1].destroy() did the trick.

0 Likes 0 ·

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.