• How to write code to click on buttons

    One of the easiest ways to get started writing Igor code is to write something that simply clicks on Asylum buttons in a certain order. Here is how to get started with that.

    1) Bring up the panel that has the button you want to click on.

    2) Hit Ctrl + T to bring up the tools for the panel.

    3) Click on the second button on the left that now shows.

    4) Double Click on the button you want to use.

    5) For buttons there are 2 things you need to get from this dialog. The Control name (First field of the control dialog), and the function the button calls (listed in the procedure popup in the control dialog). You can click on the edit button, and then copy the function's name.
    For example here is the dialog for the Do Scan Button:




    So from this you need to get that the name is DoScan_0, and the function is DoScanFunc. Since this is a button (Checkboxes, popups, etc are all different), the function has 1 argument, and it is probably a string. OK This is where things get a little complicated. Since Igor 5 we have 2 ways we can write control functions, either with a structure or with the classical input arguments. Most of our controls use the classical input arguments, but if you click on edit in the control dialog and see something like this:






    Which is the function dialog for the little "3D" buttons on the offline image graphs.
    Note that the input argument is Struct WMButtonAction &InfoStruct
    Which is the new style. So you have 3 options:
    A) Always use our function ARExecuteControl, explained below.
    B) If it is a classic style function (Single String argument), write the call to it, such as:
    DoScanFunc("DoScan_0")
    C) If it is a new style function (Single Struct argument), write the call to it, such as:
    Struct WMButtonAction &InfoStruct
    InfoStruct.CtrlName = "DisplayArgyle"
    InfoStruct.Win = "Display0Image0000" //name of graph the button is on.
    InfoStruct.EventCode = 2 //Buttons almost always get event code 2.
    InfoStruct.EventMod = 0 //This tells us things like shift click, or Ctrl click.
    //and finally call the function
    OfflineGraphFunc(InfoStruct)
    If you notice in the dialog above, we put in comments for each field of the structure we use. This is not always 100 % accurate, but should be all the fields we use most of the time. So for the example above, we use the eventMod, which if you want a normal click would be 0. Other functions may use other fields. Now if you were to do this with ARExecuteControl, it is not going to know about these other fields, so if you wanted to call the 3D button with a shift click, then you would have to write a call to OfflineGraphFunc directly.

    How to use ARExecuteControl
    This function tries to click on the control specified, it can handle buttons, Checkboxes, SetVars, Popups, or a tabControl.

    Function ARExecuteControl(ControlName,GraphStr,VarNum,VarSt r)
    String ControlName,GraphStr
    Variable VarNum
    String VarStr
    //This function executes a control of types:
    //Button, Checkbox, Popup, SetVariable, or TabControl
    //The controlName is the name of the control
    //GraphStr is the name of the window the control lives on
    //VarNum is a variable describing the state of the control you want to be in. (i.e checked for a checkbox)
    //VarStr is the same deal as VarNum, just for strings, i.e PopStr for Popups.
    //Note that for popups, VarNum is ignored, the popup list is obtained,
    //and the popNum is found based on the VarStr.


    //error returns
    //0, all is good (as far as we know)
    //1, control does not exist
    //2, Control it not a supported type
    //3, Control does not have a function to call
    //4, Number of arguments does not match control type.
    //7, Function does not exist as a user function
    //9, should be impossible, this should have exited on 2, means this function is screwed up.


    So to use ARExecuteControl, you also need to know the window name the control is on. To get that, bring up the window, and hit Ctrl + Y, copy out the name in the second field, Window Name (not window Title). The up side is that you don't need to know anything about the button's function.
    So for the DoScan button example:
    ARExecuteControl("DoScan_0","MasterPanel",0,"")
    Buttons don't use VarNum, or VarStr
    And to call OfflineGraphFunc: ARExecuteControl("DisplayArgyle","Display0Image0000",0,"")