question

Leo L6 avatar image
0 Likes"
Leo L6 asked Jason Lightfoot edited

Create Model Parameters by Code

Hello,

I'm looking for a way to create model parameters by code. One way I see this working is a script that will take in a global table with lower bound and upper bound information and generate a corresponding parameter table that can be used in the experimenter.

The first thing I thought of was to create a table class with the Parameter table and use the table methods to set parameters/parameter table size like so:1671764164030.png

However, this does not seem to work. Is the table class able to be used here or am I approaching this the wrong way?

Thank you for any help!!

FlexSim 22.0.0
flexscriptparametersparameters tableflexscript codingtable class
1671764164030.png (11.1 KiB)
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

·
Jason Lightfoot avatar image
0 Likes"
Jason Lightfoot answered Jason Lightfoot edited

Here's the working syntax for 22.0 - since you're accessing the tree structure, note that it may change in a future version:

string pTableName="Parameters";
Object paramT=Model.find("Tools/ParameterTables/"+pTableName);
Table params=paramT.find(">variables/parameters");
treenode newParam=function_s(paramT,"addParameter");
int row=newParam.rank;
params[row]["Name"]="MyNewParameter";
params[row]["Value"]=5;
params[row]["Display Units"]="cms";
params[row]["Description"]="test parameter";
treenode attrHolder=params.cell(row,"Value");
attrHolder.subnodes["type"].value=CV_TYPE_CONTINUOUS;  //also CV_TYPE_DISCRETE, INTEGER, BINARY, EXPRESSION, OPTION, PASSTHROUGH
attrHolder.subnodes["warningLevel"].value=2;
attrHolder.subnodes["lowerBound"].value=1;
attrHolder.subnodes["upperBound"].value=10;
attrHolder.subnodes["stepSize"].value=0.5;
attrHolder.subnodes["sequenceLength"].value=10;
attrHolder.subnodes["reference"].value=Model.find("Queue1");
attrHolder.subnodes["isProxy"].value=0;
// optionally add onSet
treenode onSet=function_s(attrHolder,"assertEvent","OnSet");
onSet=function_s(attrHolder,"assertEventWithCode","OnSet");
onSet.value+="// Your own set code here";
buildnodeflexscript(onSet);
· 1
5 |100000

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

Leo L6 avatar image Leo L6 commented ·
Thank you!, worked perfectly
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.