Facility Control

 View Only
  • 1.  Reset parameters button

    Posted 05-31-2017 20:13
    I'm trying to make a button that would reset a bunch of parameters at once.

    I have 10 rows layed out, and each row has a text entry box, and a toggle button.

    Each item is named logically (so text boxes have the OID's "TextEntry.1 through TextEntry.10", Buttons are given "ToggleButton.1 thorugh ToggleButton.10")

    So I know how I would script each item individually, but I'm sure there's a way to easily script it once and it would go through 1-10, but I'm not that familiar with that sort of scripting.

    Any ideas?

    Thanks


  • 2.  RE: Reset parameters button

    Posted 06-05-2017 18:04
    Hi Bamboo,

    Two quick things.

    #1: Normally I would suggest using an arry for this kind item.
    In this case your OID would be named 'TextEntry' and you would access your items as 'TextEntry[3]'.

    #2 You CAN build OIDs on the fly in Javascript.
    So, if you are unable to change your panel to use arrays, you can do something like the following:
    for (var i = 1; i <= 10; i = i + 1)
    {
    params.setValue('TextEntry.'+i,0,params.getValue('value.reset',0));
    }

    Where 'value.reset' is a parameter with the value you want to set them all to.



    Again, however, I would recommend using arrays if at all possible.

    Let me know if this works out for you.

    Troy.

    #DashBoard


  • 3.  RE: Reset parameters button

    Posted 06-20-2017 21:23
    Thanks Troy,

    I did get Method 2 to work pretty well. I don't quite understand how the arrays work, is there any info that can clarify it more? Simply renaming the parameters to "TextEntry[1]" doesn't seem to work, and I'm sure it's not supposed to.

    Just want to throw another curve in here as I move on to the next part of the project.The toggle button parameters, I'd like to make it so that when you toggle one button, the others toggle off. So it seems like it would require a similar script, the difference being that it needs to skip over itself. Here's the long script I've got working for now:

    //toggle button 3

    if (this.getValue() == '1'){

    params.setValue(ToggleButton.1, 0, 0);
    params.setValue(ToggleButton.2, 0, 0);
    //params.setValue(ToggleButton.3, 0, 0); skip itslef
    params.setValue(ToggleButton.4, 0, 0);
    params.setValue(ToggleButton.5, 0, 0);
    params.setValue(ToggleButton.6, 0, 0);
    params.setValue(ToggleButton.7, 0, 0);
    params.setValue(ToggleButton.8, 0, 0);
    params.setValue(ToggleButton.9, 0, 0);
    params.setValue(ToggleButton.10, 0, 0);
    }

    Any way to shorten this as well?

    Thanks again.
    #DashBoard


  • 4.  RE: Reset parameters button

    Posted 06-21-2017 03:52
    A couple of items.

    1: Arrays
    Arrays are a way of having a set of related variables of the same type kept together.
    A quick example would be if you wanted to store the names of 10 people, instead of declaring 10 different variables you can declare one variable and then reference them by an index.

    To declare an array parameter in DashBoard when you open the 'Add/Edit Parameters' window in edit mode in the 'Type' dropdown you would pick one of the types that end with Array, examples: 'Integer Array (32-bit)' or 'String Array'.
    This link is a good overview of Javascript and arrays:
    https://www.w3schools.com/js/js_arrays.asp


    Now....

    #2: It *looks* like you are trying to select one item from a set of 10 possibilities.
    I.e. if you want one button selected and the other 9 to not be selected.

    If that is the case, then instead of declaring 10 variables and using them as booleans do the following instead:

    2a; Create an integer parameter in the 'Add/Edit parameter' window from edit mode.
    -Type: Make it an integer (16 or 32 bit)
    -Constraint: Choose 'Choice Constraint)
    -In the Constraint Value section there is a small table of two columns.
    You will fill out 10 rows, one for each choice,
    Under the 'Value' column, just use numbers from 1 to 10.
    Under the 'Name' column, use whatever name you would want to appear on the buttons for that selection.
    -For 'Widget Hint' you will want to select 'Toggle Buttons'

    -In the Initial Value, put whichever number you want to be the default value, something from 1 to 10.

    2b; You can now put that parameter on your custom panel.
    You will notice that it draws a row of toggle buttons for you, so you will want to make it as wide as you can to show all 10 buttons.

    *note: For toggle button(s) in edit mode for that element under 'Style' you now have a 'Toggle On' and 'Toggle Off' tab, this is so you can change the style of the selected button from the unselected buttons easily without having to write any script at all.


    So, to get the behaviour I'm*guessing* you want you don't have to write a single line of script, just declare your parameter as I showed above and put it on your panel.

    If I've guessed wrong as to what you are looking at doing, let me know.
    #DashBoard


  • 5.  RE: Reset parameters button

    Posted 06-21-2017 16:33
    Hi Troy,

    Thanks for the great info about arrays, very helpful.

    We are using the toggle functions to fire xpression take ID's ("toggle on" sets a TakeID online, "toggle off" sets it to offline) So if nothing is online, none of the buttons are toggled on.

    If we went the single parameter toggle buttons route, I suppose we could add another constraint that is simply "clear," but that's not ideal as our panel is getting pretty crowded already. Plus, we would like the operator to be able to click the same button to clear the item, rather than having to click a separate button.

    Plus, if it is possible to run a loop script that skips over itself, I think that would be a good technique to learn for other situations as well.




    #DashBoard


  • 6.  RE: Reset parameters button

    Posted 06-21-2017 21:23

    Alright, so after some messing around, Here's what I have:

    var oid = 1; // <-- Match this number to button's OID
    if (this.getValue() == '1'){ // If this button is toggled on
    for (var i = 1; i <= 20; i = i + 1) { // Set the integer range (number of buttons)
    if (i === oid) continue; // this button will skip itself
    var buttons = params.getValue('ToggleButton.'+i, 0); // get all the buttons found in the range in line 3
    if (buttons == 1){
    params.setValue('ToggleButton.'+i,0,0); // If the button is turned on, it will be turned off
    }
    }
    
    ogscript.debug(oid + ' Online'); // Debug message when online
    }
    
    if (this.getValue() == '0'){
    ogscript.debug(oid + ' Offline'); // Debug message when offline
    }

    Everything is working fine, but is there a way to replace that oid variable to something closer to a "self" object? Just so I don't have to modify it for every button (since, of course, the number of buttons is continuing to grow!).

    Thanks again.


    #DashBoard


  • 7.  RE: Reset parameters button

    Posted 06-25-2017 18:58
    Hey Bamboo,

    If I had a set of actions that I wanted to do that was basically the same across a whole lot of buttons except for a number that was different I would make a global fn/api and then on each button call that function with the button number.

    So, if you had a global fn something like:

    function clearButtonsExceptOne (keep)
    {
    // do your stuff
    }

    Then on each button you would just have the text:
    clearButtonsExceptOne(6); // where 6 is the number of the button.

    This way you don't have to keep copying / pasting etc.. your code.

    To make a global function you simply need to put it in the top of your source file in an tag.

    You might have something like:


    function clearButtonsExceptOne (keep)
    {
    // do your stuff
    }

    // more global functions/apis


    Troy.

    #DashBoard


  • 8.  RE: Reset parameters button

    Posted 06-26-2017 15:30
    Thanks Troy, I'll give it a go!
    #DashBoard


  • 9.  RE: Reset parameters button

    Posted 08-07-2017 09:18
    So, I'm looking into something similar, with toggle buttons and such. And I do grasp the idea of what you're trying to do above. And sounds like you got it to work!

    However, I'm trying out the part with:

    if (this.getValue() == "1") //If this button is toggled on

    And I simply cannot get this function to work? I am told I cannot "getValue" of null (anonumousLabelTask#2) ?
    So my question would be how did you get this to work?
    #DashBoard


  • 10.  RE: Reset parameters button

    Posted 08-07-2017 11:18
    Nevermind! I figured out there are two ways to set up a toggle button.

    • One is just to set up a button and choose the toggle style/option when creating the button.
    • The other is to use the parameter version (wich in this case works like a charm).
    Create the button through the use of a parameter and it works just fine.
    Makes me somewhat wonder why it's possible to create a toggle button that you cannot read the state of through the normal "create button".
    #DashBoard