question

wl86 avatar image
1 Like"
wl86 asked Joerg Vogel edited

Unable to find slot in rack created by script

For some reason I am having trouble finding slots on racks that I've created by a script.

To illustrate, I've attached a model with two racks: one created using a script, and one created manually with identical properties. The only difference is that the "scripted" one has zoneID = 'A', whereas the manually created rack has zoneID = 'B', to distinguish the two when testing the slot finding query.

The model also contains two sample scripts: one to illustrate how I create a rack via script, the other is used to test finding slots on the two racks. Running the latter shows that finding a slot works for the manually created rack, and that it doesn't for the script rack.

Is this a bug? Am I missing something? Any help would be greatly appreciated!

Find Slot.fsm

FlexSim 22.0.16
find slotcopy rack
find-slot.fsm (41.1 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.

Jason Lightfoot avatar image
1 Like"
Jason Lightfoot answered wl86 commented

For your chosen sequence of create and copy commands you need to call OnCreate of the copied rack:

function_s(copyRack,"OnCreate");

And then reset the model.

Why can't you use the rack you create with createinstance() ?

· 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.

wl86 avatar image wl86 commented ·
Thank you Jason, that worked like a charm. And related to your question, there was no special reason to use createcopy, that was just a brain fart from my side.
0 Likes 0 ·
Clair A avatar image
3 Likes"
Clair A answered wl86 commented

@wl86 one of our users called us today for tech support with a very similar question.

Here is a small model to illustrate the bad and the good method to copy racks: createcopy Rack.fsm

Execute the 1st script:

createcopy(Model.find("Rack1"), model());

It creates a new rack, but this rack is not added to the storage system:

1701791885630.png

So any slot of this new rack will not be found in the storage system.

Test the 2nd script:

Model.find("Rack1").copy();

1701792426937.png

It creates a new rack, AND this rack is added to the storage system. By default, the copy() method fires the OnCreate event of the rack. Apparently the createcopy command does not fire this event.


1701791885630.png (21.7 KiB)
1701792426937.png (21.5 KiB)
createcopy-rack.fsm (35.6 KiB)
· 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.

wl86 avatar image wl86 commented ·
Thanks Clair, the additional explanation is appreciated.
0 Likes 0 ·