question

Jouky D avatar image
1 Like"
Jouky D asked Julie Weller commented

How to customize the meshes in the selected 3D shape with FlexScript?

Hello everyone,

I want to change by code the color of Mesh of a Shape. Normally I go to More Visuals (of the Object) and then I press the button of Customize the meshes in the selected 3D shape. After that I select a Mesh and I check Override to change the Diffuse Color. Is there a way to change the color of the mesh I want (from the object) in FlexScript?

1687855609002.png
Thank you!

FlexSim 23.1.2
3d shapemeshmore visuals
1687855609002.png (7.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.

1 Answer

·
Felix Möhlmann avatar image
0 Likes"
Felix Möhlmann answered Julie Weller commented

Any information that is unique to an object should be located in its attribute tree. If you compare a default object to one that had these values changed, you will find that making changes in the menu from your screenshot adds the following node structure to the visuals attribute subnode.

1687864870019.png

If you copy these nodes to a different object, it will use the same settings (remember to adjust the value of the shapedata node to point to the correct subnode).

And with the knowledge of where the information is stored, you can change it in code.

// Change the diffuse color
setsdtvalue(Model.find("BasicFR1>visual/localshapedata/1/block"), "diffuseColor", [0.6, 0.2, 0.8, 1]);

1687864870019.png (6.1 KiB)
· 8
5 |100000

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

Jouky D avatar image Jouky D commented ·

The localshapedata subnode only appears after I activate it manually the Customize Mesh. Is there a way to activate it with Flexscript and not using manual clicks?

And is there a way to mantain the same object color as the imported object? Why do we have to change the colors again?

0 Likes 0 ·
Felix Möhlmann avatar image Felix Möhlmann Jouky D commented ·
I don't know if there is a way to generate the simple data type node with the necessary values in FlexScript. As a workaround you could just keep an object with these nodes in the model so you can copy them to other objects.

I don't understand you second question. Any imported 3d shape should have its default coloring unless you change it. (Wasn't this your original question?)

0 Likes 0 ·
Jouky D avatar image Jouky D Felix Möhlmann commented ·
Yes, but I don't know why I have to recolor it because the colors from the original object are not the same as the ones in FlexSim. FlexSim transforms the colors to more darkness colors, that's why I have to use the option I asked.
0 Likes 0 ·
Show more comments

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.