question

Lars Jacobsen avatar image
0 Likes"
Lars Jacobsen asked Felix Möhlmann edited

How to change a TE from one type to another? I.e. Ship to Truck

Depending on some condition I would like to change a TaskExecuter from Ship to Truck on the fly. I have tried to use Object.create(TaskExecuter::Truck), but it throws an error.

I can change the ShapeIndex, but then I need to rotate the truck 90 using the ShapeFactors and I do not know how to do that using code. And the Packing method needs to be changed as well.

FlexSim 22.2.1
taskexecutorshape factors
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 Felix Möhlmann edited

I did some more digging in the tree. Those object sub types don't have their own class, which is why Object.create doesn't work.

The code that switches between them can be found in the main tree though: The changeShape code node you see marked in the screenshot (MAIN/project/library/...). If you adjust the first two variables you can run it from wherever to change the appearance of the task executer.

1661522116283.png

'obj' is a reference to the task executer, 'config' points to one of the object nodes you see under the configs tree (AGV, Truck, Airplane, Ship, Train). To turn a task executer into a ship it would be

Object obj = Model.find("TE_Name");
treenode config = maintree().find("project/library/taskexecuters/TaskExecuter>behaviour/eventfunctions/configs/Ship");
...

I am not aware that any of those have a custom packing logic. If you have those defined yourself you should be able to place them both into the same trigger and switch between them based on a label or variable value you set together when switching the visuals.


1661522116283.png (85.6 KiB)
· 3
5 |100000

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

Felix Möhlmann avatar image Felix Möhlmann commented ·

Edit: Looks like I posted a second answer instead of a comment, this was the original answer. Changed it to a comment to answer doesn't have to be re-accepted. /Edit

By default there is no "Truck" class defined in FlexSim's library. If you want to create a flowitem truck or an object you added as part of a user library, you would use the "createcopy()" command.

treenode Truck = createcopy(Model.find("Tools/FlowItemBin/Truck/1"), model());
treenode Truck = createcopy(maintree().find("project/userlibrary/UserLibrary 1/Truck1"), model());

Another approach could be to have both objects in the model at all times and hide their 3d shape while they are not used ('switch_hideshape(object, 0/1)').

0 Likes 0 ·
Lars Jacobsen avatar image Lars Jacobsen Felix Möhlmann commented ·

The Task Executor "TaskExecutor" have 5 sub types and I would like to change the type on the fly if possible.


1661518271359.png

0 Likes 0 ·
1661518271359.png (63.6 KiB)
Lars Jacobsen avatar image Lars Jacobsen commented ·
Thanks!!!
0 Likes 0 ·