question

Wang Z2 avatar image
0 Likes"
Wang Z2 asked Joerg Vogel answered

Calling values in other user command tree nodes

I want calling values in other user command tree nodes.

for example,In my model, I created a new treenode (called “number1”) in "command1", now I want to call this value in command2, how to write the code.

Thanks a lot.

FlexSim 18.2.3
codeuser commandtreenode
15506451661.jpg (6.5 KiB)
· 2
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 ·
@Wang Z2

If you could send in your model or a sample model then we would be able to see exactly what you are trying to do. The easy answer, I think, might be to just write that value to a Global Variable instead of to a treenode?

1 Like 1 ·
Wang Z2 avatar image Wang Z2 Jeff Nordgren commented ·

Thanks for your advice.Global Variable is a better choice

0 Likes 0 ·

1 Answer

·
Joerg Vogel avatar image
0 Likes"
Joerg Vogel answered

You use the sampler tool and get a treenode reference to the node:

Model.find("Tools/UserCommands/command1/number1")

Then you need to get the value of this node:

Model.find("Tools/UserCommands/command1/number1").value

If you want to see that this works, you can write in the command2() the print command:

print(Model.find("Tools/UserCommands/command1/number1").value);

If you reset the model and execute the user command "command2()" in a script console window the value of the node is written in the output console.


5 |100000

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

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.