Is there a way to define a global variable using code, and specify its parameters?
Is there a way to define a global variable using code, and specify its parameters?
I'm always hesitant to suggest digging into tree internals because it can cause compatibility issues if/when we change those tree internals. So, use at your own risk.
If you have an existing Global Variable, you can view the structure in your model tree under MODEL:/Tools/GlobalVariables. There you can browse the structure and see how they are set up.
To create another global variable programmatically, the easiest way would be to create a copy of an existing GV, then modify it, and finally call refreshglobalvariables() to register your new GV since it was added dynamically. Keep in mind that this command does have the side effect of resetting all your GVs to their initial value, so if you are trying to do this during a model run, its not a good idea.
Here is some example code to get you started:
treenode GVs = node("MODEL:/Tools/GlobalVariables"); treenode newGV = createcopy(first(GVs), GVs); //change the name of the new Global Variable setname(newGV, "myNewGV"); sets(first(newGV), "myNewGV"); //give the newGV a new data type. Try creating them using // the normal GUI interface to see what all the types are set(rank(newGV, 2), 1); //set new data as the initial value of newGV. This is // ALWAYS saved as a string, even if it is numeric data sets(rank(newGV, 3), "4321"); //finally, refresh the global variables. This registers // newGV as a GV so it can be used, but also resets all // GVs back to their initial value refreshglobalvariables(); //you can now use myNewGV as a normal Global Variable
3 People are following this question.
FlexSim can help you understand and improve any system or process. Transform your existing data into accurate predictions.
FlexSim is a fully 3D simulation software environment. FlexSim can be used to simulate any process in any industry.
FlexSim®, FlexSim Healthcare™, Problem Solved.®, the FlexSim logo, the FlexSim X-mark, and the FlexSim Healthcare logo with stylized Caduceus mark are trademarks of FlexSim Software Products, Inc. All rights reserved.
Privacy | Do not sell or share my personal information | Cookie preferences | Report noncompliance | Terms of use | Legal | © Autodesk Inc. All rights reserved