Hi,
is it possible to insert global variable (both int/doble both array) and global table directly by script?
Thank you all!
Hi,
is it possible to insert global variable (both int/doble both array) and global table directly by script?
Thank you all!
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());
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?
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();
9 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 | © 2025 Autodesk Inc. All rights reserved