User Tools

Site Tools


chataigne

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
chataigne [2023/02/07 06:57] – [object] ssm2017chataigne [2023/02/17 17:54] (current) – [Values in script] ssm2017
Line 13: Line 13:
 my_instance.mymethod(["test","one","two"]); my_instance.mymethod(["test","one","two"]);
 script.log(my_instance.myprop1); script.log(my_instance.myprop1);
 +</sxh>
 +===== Values in script =====
 +When adding a value parameter in a module, only the parameter is saved between sessions/projects. If you want to keep the value content, use setAttribute("saveValueOnly",false)
 +<sxh js>
 +var mycontainer = local.values.addContainer("toto");
 +var myint1 = mycontainer.addIntParameter("myint", "",1,1,65536);
 +myint1.setAttribute("saveValueOnly",false);
 +</sxh>
 +===== Custom variables =====
 +<sxh js>
 +function getCustomVariablesGroup(name, shortname) {
 +  var my_group = root.customVariables.getItemWithName(shortname);
 +  if (my_group.name != shortname) {
 +    // build a new group
 +    my_group = root.customVariables.addItem(shortname);
 +    my_group.setName(name);
 +  }
 +  return my_group;
 +}
 +
 +/**
 + * Set or create then set the custom variable value
 + * @param {int} page_id 
 + * @param {int} exec_id 
 + * @param {int} value 
 + * @param {string} type 
 + * @param {string} item_nice_name 
 + */
 +function setCustomVariablesValue(page_id, exec_id, value, type, item_nice_name) {
 +  // build names
 +  var shortname = "exec"+ page_id+ "_"+ exec_id;
 +  var name = "Exec "+ page_id+ "_"+ exec_id;
 +  // get the group
 +  var my_group = getCustomVariablesGroup(name, shortname);
 +  // define the item type
 +  var item_name = type;
 +  var item_type = "Int";
 +  var int_max = 100;
 +
 +  if (["Go", "Stop", "Resume", "Off"].contains(type)) {
 +    item_type = "Bool";
 +  }
 +  // build some names
 +  var my_value = {};
 +  var my_value_name = "exec"+ page_id+ "_"+exec_id+ item_name;
 +  var my_value_nice_name = "Exec "+ page_id+ "_"+ exec_id+ " "+ item_nice_name;
 +
 +  var my_value_item = my_group.variables.getItemWithName(my_value_name);
 +  if (my_value_item.name != my_value_name) {
 +    // create if not exist
 +    my_value_item = my_group.variables.addItem(item_type+ " Parameter");
 +    my_value = my_value_item.getChild(my_value_item.name);
 +    my_value.setName(my_value_nice_name);
 +
 +    if (["CueMsb", "CueLsb"].contains(type)) {
 +      int_max = 999;
 +    }
 +    if (["Hour", "Minute", "second"].contains(type)) {
 +      int_max = 60;
 +    }
 +    if (!["Go", "Stop", "Resume", "Off"].contains(type)) {
 +      my_value.setRange(0,int_max);
 +    }
 +  }
 +  else {
 +    my_value = my_value_item.getChild(my_value_item.name);
 +  }
 +  if (["Go", "Stop", "Resume", "Off"].contains(type)) {
 +    my_value.set(true);
 +    my_value.set(false);
 +  }
 +  else {
 +    my_value.set(value);
 +  }
 +  my_group.variables.reorderItems();
 +}
 </sxh> </sxh>
chataigne.1675749476.txt.gz · Last modified: by ssm2017