question

Leo L6 avatar image
0 Likes"
Leo L6 asked IEThai commented

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
flexscriptparametersflexscript codingparameters tabletable 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 IEThai commented

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

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

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