question

hermione12 avatar image
0 Likes"
hermione12 asked hermione12 commented

Create object using custom code

In my model, I want to generate 25 items on floor storage type rack using code (no process flow).

Unless I connect source to floor storage, it is not generating any item. After I connect source and use the createcopy(), it is generating 150 items for the one time looping in the source inter-arrival code.

Also I want to assign label to each item through code. The labels should be assigned during the generation of the items.

Can you please help? @Felix Möhlmann

Create_object_using code.fsm



FlexSim 20.0.10
createcopyinter-arrival
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

·
Felix Möhlmann avatar image
0 Likes"
Felix Möhlmann answered hermione12 commented

Where did you put the code before adding the source?

You always need some event to trigger the execution of the code. The 'On Run Start' model trigger might be a good option for this.

1658483747340.png

Instead of creating the item directly in the storage, you might want to first create them in the model and then move them into the storage ('moveobject(object, destination)'). Otherwise the placement logic won't work correctly.

The 'createcopy()' command returns a reference to the created object (which you already assign to the 'item' variable). As such you can assign labels with the normal syntax (item.labelName = value).

if(Model.time == 0) // Only on first start
{
    // Get references to reuse them in the loop
    Object destination = Model.find("FloorStorage1");
    treenode flowItem = Model.find("/Tools/FlowItemBin/Box/1");
   
    for(int i = 1; i <= 25; i++)
    {
       Object item = createcopy(flowItem, model());
       item.creationRank = i;
       moveobject(item, destination);
    }
}

Because you put the code in the inter-arrival time but don't return any value (the time value that is expected from the code), the value is assumed to be zero and the inter-arrival time triggers again immediately. This repeats until the storage is full.

create-object-using-code-fm.fsm


· 12
5 |100000

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

hermione12 avatar image hermione12 commented ·

Thank you @Felix Möhlmann , If i want to assign label in the code to each box?

Also I want to generate boxes on top of pallets, how to do this purely with code OnRunStart?

0 Likes 0 ·
Felix Möhlmann avatar image Felix Möhlmann hermione12 commented ·

"If i want to assign label in the code to each box?"

That is what the code in my answer does. Could you specify what should be different to the way the way that code works?

To generate the boxes on pallets, create a pallet. For that just adjust the path in the find() command to refer to the pallet flow item instead. Then move the box into the pallet with 'moveobject(object, destination)'.

0 Likes 0 ·
hermione12 avatar image hermione12 Felix Möhlmann commented ·
Yes , I am able to generate boxes on pallets using the commands. Thank you

"To assign label"

I want to assign particular part number to each part. The creationrank assigns unique numbers to all the parts. Similarly I want to assign part name as "Part1", "Part2"...

How to do that?

0 Likes 0 ·
Show more comments

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.