How to Change Object Shape Visualization in Flexscript

How to Change Object Shape Visualization in Flexscript

julius_j2
Not applicable
7,676 Views
6 Replies
Message 1 of 7

How to Change Object Shape Visualization in Flexscript

julius_j2
Not applicable

[ FlexSim 21.2.4 ]

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.

0 Likes
Accepted solutions (1)
7,677 Views
6 Replies
Replies (6)
Message 2 of 7

kavika_faleumu
Autodesk
Autodesk
Accepted solution

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

0 Likes
Message 3 of 7

kavika_faleumu
Autodesk
Autodesk

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
Message 4 of 7

julius_j2
Not applicable

Thank you for your answer!

0 Likes
Message 5 of 7

julius_j2
Not applicable

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
Message 6 of 7

julius_j2
Not applicable
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
Message 7 of 7

kavika_faleumu
Autodesk
Autodesk

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