question

Julius J2 avatar image
0 Likes"
Julius J2 asked Kavika F commented

How to Change Object Shape Visualization in Flexscript

I tried to change the shape visualization of an object, in my case a processor. The default would be

fs3d\Processor\Processor.3ds

How to change this if I already created the object with the code below?

Object ProcessorPath = createinstance(library().find("?Processor"), PlatformPath);

I tried using setobjectshapeindex but it failed. Thank you.

FlexSim 21.2.4
flexscriptprocessorobjectvisualization3d object
· 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.

Kavika F avatar image Kavika F ♦ commented ·

Hi @Julius J2, was Kavika F's answer helpful? If so, please click the "Accept" button at the bottom of their answer. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.

0 Likes 0 ·

1 Answer

·
Kavika F avatar image
0 Likes"
Kavika F answered Kavika F commented

Hey @Julius J2, setobjectshapeindex seemed to work for me. Here's my script:

Object processor = createinstance(library().find("?Processor"), model());
setobjectshapeindex(processor, getshapeindex("fs3d\\General\\Box.3ds"));

You can save the result of the createinstance function in an object variable (I called mine "processor"). The first parameter of createinstance is the object that you want to create and the second parameter is where you want to put it (in this case I just put it in the model() wherever it decides). Then you can set the shape of the object using setobjectshapeindex like above. It takes in the object you want to change as the first parameter and then an index of the new shape. These indices can be found in View -> Media Files; ensure that "Shapes" is selected at the top of the menu and then below is a dropdown list of different shapes and their indexes (on the left of the name).

If you run the script of the model I've attached, it should spawn a processor in the model that looks like a box. However, if you reset the model, it will go back to looking like a processor. I have two scripts saved in the model that you can load: "Make Processor Box" which will create a processor and change its shape to a box; and "Update to Box" which will simply change whatever shape I've got the reference to back into a box:

setobjectshapeindex(Model.find("Processor1"), getshapeindex("fs3d\\General\\Box.3ds"));

If you run Update to Box after a reset, it will change the processor back into a box. You can run the model and it will carry out like normal.

Does this answer your question? If not, please provide some more details so I can understand your problem better. A test file could be helpful too if you've got one.

update-shape.fsm


update-shape.fsm (27.7 KiB)
· 4
5 |100000

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

Julius J2 avatar image Julius J2 commented ·

Thank you for your answer!

0 Likes 0 ·
Julius J2 avatar image Julius J2 commented ·

For me this is still not working. I want to change a processor into a table. Manually, I can change it in Visual properties. The object model path is:

modules\People\shapes\locations\table.3ds

When I tried using the setobjectshapeindex, the table object can't be resized into the size I want, so the shape will be like this:

1.png

And if I change it manually in Visual properties, the shape will be right like this:

2.png

0 Likes 0 ·
1.png (12.3 KiB)
2.png (31.2 KiB)
Julius J2 avatar image Julius J2 commented ·
and also I'm so sorry, I can't open your model since it is from 22 version. My FlexSim version is 21. Thanks
0 Likes 0 ·
Kavika F avatar image Kavika F ♦ Julius J2 commented ·

Ok, here's a version that should be in 21.2. Also, I changed the script so that it will change the shape of the object and apply it so that when you reset the model it maintains that shape. I use Object.setProperty() to change the processor's shape. Here is an overview of different properties that method can change. If you want to change the size of the shape programmatically, you can also use the set Property function with Size.X, Size.Y, and Size.Z as the parameters and specify the sizes you want (see the bottom of the "General Properties" page linked above).

update-shape2.fsm

0 Likes 0 ·
update-shape2.fsm (25.1 KiB)

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.