591
Mach4 General Discussion / Re: Using a button script to set jog increments etc
« on: May 25, 2018, 05:52:09 PM »
For that, you will most definitely have to use the screen API.
If you open up the screen editor and look at the properties of a regular button, you will see a property called "Bg Color". This is the property you will want to set with scr.SetProperty(). The property is editable in the screen editor with a color picker control. But it is actually stored as a string. A call to scr.GetProperty("myButton", "Bg Color") will reveal the stored value. If the returned sting is blank/empty, then the default color based on the current Windows theme will be used. Otherwise, it will return a value in HTML RGB format like "#RRGGBB" #FF0000 is pure red, #00FF00 is pure green, #0000FF is pure blue. Any color can be represented with this syntax.
An easy way to get the value for the color you want is to open the screen editor, set a button's "Bg Color" to the color you want, and then use scr.GetProperty("myButton", "Bg Color") to get the value. Record it, and then maybe change the color and get more values. Otherwise, there are probably lots of color picker tools out there that are capable of doing this too.
Once you have your color values, then you can set the button color based on the current jog increment in the PLC script.
Steve
string: value, number: rc = scr.GetProperty(string: ctrlName, string: propertyName)
number: rc = scr.SetProperty(string: ctrlName, string: propertyName, string: value)
The control name is the name you have given the screen element in the Name property. It is case sensitive.
The property name is the name of the property as spelled in the property grid. Value, for example. Or Top, Left, Width, Height, etc...
The value of the property is always a string. Use tonumber() to convert a string to a number in LUA. Conversely, use tostring() to convert a number to a string. Some properties are lists, which have values associated with the string description in the list. In this case, you will get the value instead of the string description.
If you open up the screen editor and look at the properties of a regular button, you will see a property called "Bg Color". This is the property you will want to set with scr.SetProperty(). The property is editable in the screen editor with a color picker control. But it is actually stored as a string. A call to scr.GetProperty("myButton", "Bg Color") will reveal the stored value. If the returned sting is blank/empty, then the default color based on the current Windows theme will be used. Otherwise, it will return a value in HTML RGB format like "#RRGGBB" #FF0000 is pure red, #00FF00 is pure green, #0000FF is pure blue. Any color can be represented with this syntax.
An easy way to get the value for the color you want is to open the screen editor, set a button's "Bg Color" to the color you want, and then use scr.GetProperty("myButton", "Bg Color") to get the value. Record it, and then maybe change the color and get more values. Otherwise, there are probably lots of color picker tools out there that are capable of doing this too.
Once you have your color values, then you can set the button color based on the current jog increment in the PLC script.
Code: [Select]
if (incr == .001) then
rc = scr.SetProperty("myButton", "Bg Color", "#FF0000") -- set button color to red if incr == .001
elseif (incr == .01) then
rc = scr.SetProperty("myButton", "Bg Color", "#00FF00") -- set button color to green if incr == .01
elseif (incr == .1) then
rc = scr.SetProperty("myButton", "Bg Color", "#0000FF") -- set button color to blue if incr == .1
end
Steve