User fields and checkboxes...

If you have a question about the software please ask it here.

User fields and checkboxes...

Postby A_Camera » Thu Apr 27, 2017 6:52 pm

Hi,

Just installed the latest release and I like some of the new features. It is grate that the user fields and checkboxes ID>= 20000 are saved in the profile, but is there a good example of how to use the saved value? I mean, do I have to open the file, find the right label, read the value and write it back into the field every time after start, or is there an automatic way?

This is what I am trying to do: I want to use the B and C axis fields for something else and also as global values to be passed on to a lot of other macros. I change the label to 20002 and 20003 from 230 and 231. This works fine, I can use the fields, enter values and the "Zero All" button does not change them back to zero. When I close UCCNC, I can see that the values are saved in the profile, but when I start UCCNC the fields display zero, not the values which are saved in the profile file.

If I don't change the label numbers and just keep 230 and 231 then this is not an issue, the values are saved and when UCCNC is started the next time the saved values are placed in the fields. This is fine for me, I can use any labels, but the problem is that the "Zero All" button would clear the values.

I could rewrite the macro for the "Zero all", but the question is, does that button do anything more than:

exec.Setvar(0, Xvar);
AS3.Setfield(0, Xdro);
AS3.Validatefield(Xdro);

...repeated for each axis, or is that button doing something else also? Rewriting the Zero All is the easiest approach, much easier than having to open the file and look for the right user field label, reading the value and so on... just to get the field updated every time UCCNC is started.

Or, is there an automatic/better way to do this?

Thanks for the help.
A_Camera
 
Posts: 639
Joined: Tue Sep 20, 2016 11:37 am

Re: User fields and checkboxes...

Postby dezsoe » Thu Apr 27, 2017 9:13 pm

I think using the B and C axes to store information is not the best practise. :) Use your own fields.

The easyest way to reload values on startup is to use one of the following lines in the M99998.txt macro:
Code: Select all
AS3.Setfield(Convert.ToDouble(exec.Readkey("UserTextfields", "20002", "0.0")), 20002); // Set numeric field
AS3.Setfieldtext(exec.Readkey("UserTextfields", "20003", "default text"), 20003); // Set text field

The exec.Readkey function returns the stored STRING from the current profile. So, in the first example it has to be converted to double, because Setfield works with double. In the second example it is not converted.

Readkey has 3 parameters. First is the key where the value will be stored: "UserTextfields". The second is the name of the value to return. The third is a default value: if the key or the name is not found, this default value will be returned.

Also, you can save values in the M99999.txt macro when exiting UCCNC. For example you can save and reload the state of LED 999:
Code: Select all
exec.Writekey("MyValues", "MyLEDState", exec.GetLED(999).ToString()); // M99999 save

Code: Select all
exec.SetLED(Convert.ToBoolean(exec.Readkey("MyValues", "MyLEDState", "false")), 999); // M99998 load and set

The result in the profile will be (if LED is on):
Code: Select all
[MyValues]
MyLEDState=True
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: User fields and checkboxes...

Postby ger21 » Thu Apr 27, 2017 9:48 pm

dezsoe wrote:The easyest way to reload values on startup is to use one of the following lines in the M99998.txt macro:


+1
This is what I do, and I'm the one that got that feature added. My Constructor macro has a lot of these in it:

readfield = exec.Readkey("UserTextfields", "20330", "0.000");
AS3.Setfieldtext(readfield, 20330); // Set Park #4 X Value
AS3.Validatefield(20330);
Gerry
UCCNC 2022 Screenset - http://www.thecncwoodworker.com/2022.html
ger21
 
Posts: 2714
Joined: Sat Sep 03, 2016 2:17 am

Re: User fields and checkboxes...

Postby A_Camera » Fri Apr 28, 2017 7:08 am

Szia Csaba, Köszi a segitséget!

dezsoe wrote:I think using the B and C axes to store information is not the best practise. :) Use your own fields.


I agree, that's what I wanted to do, but did not want to write file handlers if there is already a better way, which I suspected that there was. Otherwise B and C would be usable for me, even if it is not the best practice.

dezsoe wrote:The easyest way to reload values on startup is to use one of the following lines in the M99998.txt macro:
Code: Select all
AS3.Setfield(Convert.ToDouble(exec.Readkey("UserTextfields", "20002", "0.0")), 20002); // Set numeric field
AS3.Setfieldtext(exec.Readkey("UserTextfields", "20003", "default text"), 20003); // Set text field

The exec.Readkey function returns the stored STRING from the current profile. So, in the first example it has to be converted to double, because Setfield works with double. In the second example it is not converted.

Readkey has 3 parameters. First is the key where the value will be stored: "UserTextfields". The second is the name of the value to return. The third is a default value: if the key or the name is not found, this default value will be returned.

Also, you can save values in the M99999.txt macro when exiting UCCNC. For example you can save and reload the state of LED 999:
Code: Select all
exec.Writekey("MyValues", "MyLEDState", exec.GetLED(999).ToString()); // M99999 save

Code: Select all
exec.SetLED(Convert.ToBoolean(exec.Readkey("MyValues", "MyLEDState", "false")), 999); // M99998 load and set

The result in the profile will be (if LED is on):
Code: Select all
[MyValues]
MyLEDState=True


Excellent help, very good description of functions I never knew existed! Exactly what I was looking for, plus more. I will definitely try it tonight. :)

Thanks a lot.
A_Camera
 
Posts: 639
Joined: Tue Sep 20, 2016 11:37 am

Re: User fields and checkboxes...

Postby A_Camera » Fri Apr 28, 2017 7:13 am

ger21 wrote:
dezsoe wrote:The easyest way to reload values on startup is to use one of the following lines in the M99998.txt macro:


+1
This is what I do, and I'm the one that got that feature added. My Constructor macro has a lot of these in it:

readfield = exec.Readkey("UserTextfields", "20330", "0.000");
AS3.Setfieldtext(readfield, 20330); // Set Park #4 X Value
AS3.Validatefield(20330);

Yes, I knew you requested this feature but user requests are only as useful as the documentation of them. If a feature is undocumented it is only usable for a small elite group. Anyway, thanks for requesting this and for the example above.
A_Camera
 
Posts: 639
Joined: Tue Sep 20, 2016 11:37 am

Re: User fields and checkboxes...

Postby A_Camera » Sat Apr 29, 2017 5:46 pm

It is nice and is working, but...

If I click in the field and not change the value, just leave and click in another field, the value which was in the field is lost. This is not the case with the axis DRO fields, so how can i preserve the value and prevent that the value is lost because of a mistake?

Code: Select all
AS3.Setfield(Convert.ToDouble(exec.Readkey("UserTextfields", "20002", "0.0")), 20002); // Set numeric field
AS3.Validatefield(20002);
AS3.Setfield(Convert.ToDouble(exec.Readkey("UserTextfields", "20003", "0.0")), 20003); // Set numeric field
AS3.Validatefield(20003);


My M99998.txt contains the above, but the Validatefield does not seem to make a difference.
A_Camera
 
Posts: 639
Joined: Tue Sep 20, 2016 11:37 am

Re: User fields and checkboxes...

Postby ger21 » Sat Apr 29, 2017 5:55 pm

If I click in the field and not change the value, just leave and click in another field, the value which was in the field is lost.


Mine don't do that.
I can click from field to field, and all of the values remain.
Gerry
UCCNC 2022 Screenset - http://www.thecncwoodworker.com/2022.html
ger21
 
Posts: 2714
Joined: Sat Sep 03, 2016 2:17 am

Re: User fields and checkboxes...

Postby A_Camera » Sat Apr 29, 2017 9:22 pm

Probably my mistake. Don't know what's wrong, will continue tomorrow. Too late here now.
A_Camera
 
Posts: 639
Joined: Tue Sep 20, 2016 11:37 am

Re: User fields and checkboxes...

Postby shakil1740 » Sun Jan 22, 2023 12:45 am

Thanks for reply.
shakil1740
 
Posts: 9
Joined: Mon Jul 11, 2022 8:22 pm

Re: User fields and checkboxes...

Postby Battwell » Sun Jan 22, 2023 12:55 pm

i didnt know that the user fields and checkboxes ID>= 20000 are saved in the profile.
would have saved a lot of extra code in my latest macros!
what version was this implemented?
Uc300eth on router and mill.
UK uccnc powered machine sales. https://cncrouter.uk/atc-cnc-routers.htm
Automateanything/duzzit cnc/mercury cnc
Battwell
 
Posts: 867
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk

Next

Return to Ask a question from support here

Who is online

Users browsing this forum: Bing [Bot] and 12 guests

cron