Global variable and Global table by script

Global variable and Global table by script

alfredo_df2
Not applicable
61 Views
3 Replies
Message 1 of 4

Global variable and Global table by script

alfredo_df2
Not applicable

[ FlexSim 17.2.5 ]

Hi,

is it possible to insert global variable (both int/doble both array) and global table directly by script?

Thank you all!

0 Likes
Accepted solutions (1)
62 Views
3 Replies
Replies (3)
Message 2 of 4

joerg_vogel_HsH
Mentor
Mentor
Accepted solution

The last part of your question has answered @steven.hamoen already at "create a Global Table in flexscript". Maybe you adjust my answer at the same question there to add global variables by source code.

EDIT: Try for Global Variables

treenode globalVariableNode = model().find("Tools/GlobalVariables");
treenode newVariable = createcopy(globalVariableNode.first,globalVariableNode,0);
newVariable.name = "myNewVariable";
newVariable.subnodes[1].value = "myNewVariable";
newVariable.subnodes[2].value = 4; // Type 1: int/ 2: double/ 3: treenode/ 4: string /5: Array
newVariable.subnodes[3].dataType = DATATYPE_STRING;
newVariable.subnodes[3].value = "MyData";// Array entries as Subnodes, Datatype is string 
refreshglobalvariables();
buildnodeflexscript(model());
treenode globalVariableNode = model().find("Tools/GlobalVariables");
treenode newVariable = createcopy(globalVariableNode.first,globalVariableNode,0);
newVariable.name = "myNewVariable";
newVariable.subnodes[1].value = "myNewVariable";
newVariable.subnodes[2].value = 5; // Type 1: int/ 2: double/ 3: treenode/ 4: string /5: Array
newVariable.subnodes[3].dataType = DATATYPE_STRING;
newVariable.subnodes[3].value = "1";// Array entries as Subnodes, Datatype is string 
newVariable.subnodes[3].subnodes.assert("1","3"); // the node name is typically blank
// then you can only add one entry
newVariable.subnodes[3].subnodes.assert("2","newvalue");
newVariable.subnodes[3].subnodes.assert("3","ddd");
refreshglobalvariables();
buildnodeflexscript(model());

0 Likes
Message 3 of 4

yue_y
Not applicable

This assumes we already have a global variable so that we can create a copy of it. What if there is no global variable at all?

0 Likes
Message 4 of 4

Matthew_Gillespie
Autodesk
Autodesk

Just add the nodes yourself:

string varName = "MyVariable";
treenode globalVariables = Model.find("Tools").subnodes.assert("GlobalVariables");
treenode newVariable = globalVariables.subnodes.add();
newVariable.name = varName;

newVariable.subnodes.assert("Name").value = varName;
newVariable.subnodes.assert("Type").value = 1;
newVariable.subnodes.assert("Data").value = 0;

refreshglobalvariables();


Matthew Gillespie
FlexSim Software Developer

0 Likes