How to change the operator shape using code?

How to change the operator shape using code?

tomi_kosunen
Not applicable
43 Views
5 Replies
Message 1 of 6

How to change the operator shape using code?

tomi_kosunen
Not applicable

[ FlexSim 17.2.1 ]

Thru UI it is possible to set Operator shape to Male/Female/Legacy Operator. Is it possible to make the selection from code (On Model Reset)? I have tried to set the Operators ">visual/shape" and ">visual/shapeindex" values in the tree but it won't work.

0 Likes
Accepted solutions (1)
44 Views
5 Replies
Replies (5)
Message 2 of 6

jeff_nordgren
Not applicable

@tomi.kosunen,

Have you considered making 3 different operator shapes. Then just use the proper shape rather than trying to change the current shape on the fly. Use three shapes and just switch shapes instead. Just a thought.

Thanks.

Message 3 of 6

jeff_nordgren
Not applicable
@tomi.kosunen

Did you get an answer to your question?

0 Likes
Message 4 of 6

tomi_kosunen
Not applicable

I would like to change the shape on the fly if possible.

0 Likes
Message 5 of 6

christian_norregaard
Not applicable

Tomi,

Would it be an option to use three different frames on the operator, and then simply use "setframe(operator,FrameName)" when you wish to change the shape? In that case, it could easily be done on the fly.

Best regards
Christian

Message 6 of 6

jeff_nordgren
Not applicable
Accepted solution

@tomi.kosunen

The code that you would use to change the shape of an object is this:

setobjectshapeindex(model().find("Operator1"),111); // Female

Where "model().find("Operator1")" is the object to change and "111" is the index shape number. You can find (and add shapes) the shape number by going to the View>Media Files menu option. From there you can click on the down arrow for index numbers of shapes that are loaded by default. If your shape is not there (like a female operator) then you can use the Browse button to go to where that shape is and select it. Then you press the Add button to add it to the preloaded shapes and images. It will assign a new shape ID, such as 111, which you can then use in code to change the shape of an object.

As far as changing in the UI, it doesn't seem to like that. It will revert back to a male operator. The way to do that would be to just add another flowitem called "Female" (or something similar).

When trying to change the shape on Reset, there are a lot of places that can overwrite your code if not put in the right place. I found rather than put it in the OnModelReset code area (where it gets overwritten later in the Reset cycle) I put it in the OnRunStart. That way all the Reset code has fired so when you press the Run button, the shape will change at that point.

9640-female.png