question

Tomi Kosunen avatar image
0 Likes"
Tomi Kosunen asked Jeff Nordgren answered

How to change the operator shape using code?

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.

FlexSim 17.2.1
operatorshape
· 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.

Jeff Nordgren avatar image Jeff Nordgren commented ·

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

1 Like 1 ·
Jeff Nordgren avatar image Jeff Nordgren commented ·
@tomi.kosunen

Did you get an answer to your question?

0 Likes 0 ·
Tomi Kosunen avatar image Tomi Kosunen commented ·

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

0 Likes 0 ·
Jeff Nordgren avatar image
3 Likes"
Jeff Nordgren answered

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



female.png (70.5 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.

christian.n avatar image
1 Like"
christian.n answered

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

5 |100000

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