question

Alfredo DF2 avatar image
0 Likes"
Alfredo DF2 asked Matthew Gillespie commented

Global variable and Global table by script

Hi,

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

Thank you all!

FlexSim 17.2.5
global tablescriptglobal variablesdebug
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

·
Joerg Vogel avatar image
0 Likes"
Joerg Vogel answered Matthew Gillespie commented

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());

· 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.

Yue Y avatar image Yue Y commented ·

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 0 ·
Matthew Gillespie avatar image Matthew Gillespie ♦♦ Yue Y commented ·

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();
0 Likes 0 ·

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.