Changing a checkbox via AS3.Switchbutton doesn't work ?

This is where you talk about Macros, show examples of your macro scripting and SHARE handy segments of script code as examples.

Changing a checkbox via AS3.Switchbutton doesn't work ?

Postby andrewwong2000 » Sat Jan 15, 2022 10:40 am

Hi all,

I have written a macro to switch between 2 different probes (touchplate & sensor).

Touchplate is on Pin 10 Port 1 ActiveLow (NO)
Probe is on Pin 11 Port 1 ActiveHigh (NC)

The following macro gets called to toggle Probe 1 between the 2 probes.

All works fine with the fields, but I cannot get the Checkbox to change state...
After running the macro, the checkbox for ActiveLow gets toggled in the screen (2017).. but it doesn't change the state.

Hitting "Apply Settings" doesn't apply the change in ActiveLow/High .. unless I go and use the GUI to toggle the checkbox twice with my mouse.

Appreciate any advice . Thanks !

---
//Function: string Getfield(int fieldnumber)
//Function: void Setfield(double value, int fieldnumber)
//Function: void Validatefield(int fieldnumber)
//Function: void Setfieldtext(string value, int fieldnumber)
//Function: bool Getbuttonstate(int buttonumber)
//Function: void Switchbutton(bool Ison, int Buttonnumber)
//string fieldvalue = AS3.Getfield(100);
//AS3.Setfield(15.23, 100);

exec.AddStatusmessage("Toggle Probe Script");
string CurrentProbePin = AS3.Getfield(92);
string CurrentProbePort = AS3.Getfield(272);
bool CurrentProbeActiveLow = AS3.Getcheckboxstate(56);
string ProbeName = "";

exec.AddStatusmessage("Current Probe Status = Pin " + CurrentProbePin + " Port " + CurrentProbePort + " ActiveLow = " + CurrentProbeActiveLow);

// Flip Variables
if (CurrentProbePort != "1")
{
CurrentProbePort = "1";
}

if (CurrentProbePin == "11")
{
CurrentProbePin = "10";
CurrentProbeActiveLow = true;
ProbeName = "Touchplate";
}
else
{
CurrentProbePin = "11";
CurrentProbeActiveLow = false;
ProbeName = "Probe";
}

AS3.Setfieldtext( CurrentProbePin, 92);
AS3.Validatefield( 92 );
AS3.Setfieldtext( CurrentProbePort, 272);
AS3.Validatefield( 272 );
AS3.Switchbutton( false, 20417);
exec.Wait(50);
AS3.Switchbutton( CurrentProbeActiveLow, 20417); // This command works in the screenset but doesn't affect the UCCNC system.. are checkboxes really readonly via macro ?
AS3.Setfieldtext( ProbeName, 20001);

exec.Callbutton(168); // apply all settings
exec.Wait(50);
//exec.Callbutton(167); // save all settings

exec.AddStatusmessage("New Probe Status = Pin " + CurrentProbePin + " Port " + CurrentProbePort + " ActiveLow = " + CurrentProbeActiveLow);
andrewwong2000
 
Posts: 29
Joined: Sun Nov 25, 2018 12:57 pm

Re: Changing a checkbox via AS3.Switchbutton doesn't work ?

Postby ger21 » Sat Jan 15, 2022 12:58 pm

2017 checkboxes are buttons, not checkboxes.

Instead of switchbutton(20417), try Callbutton(20417). This should actually press the button,resulting in the button macro switching the checkbox. This would be my preferred method if it works.
Or, when you call Switchbutton(20417), also call Setcheckboxstate for checkbox 56.

Here's the code for the 20417 button

Code: Select all
bool buttonstate = AS3.Getbuttonstate(20417);

if (buttonstate)
{
   AS3.Setcheckboxstate(false, 56);
   AS3.Switchbutton(false,20417);
}
else
{
   AS3.Setcheckboxstate(true, 56);
   AS3.Switchbutton(true,20417);
}
Gerry
UCCNC 2022 Screenset - http://www.thecncwoodworker.com/2022.html
ger21
 
Posts: 2794
Joined: Sat Sep 03, 2016 2:17 am

Re: Changing a checkbox via AS3.Switchbutton doesn't work ?

Postby andrewwong2000 » Sat Jan 15, 2022 11:40 pm

Awesome thanks Gerry!
andrewwong2000
 
Posts: 29
Joined: Sun Nov 25, 2018 12:57 pm


Return to Macros

Who is online

Users browsing this forum: No registered users and 1 guest