Page 1 of 1

Macro Run on field change event? And other questions...

PostPosted: Sat Aug 18, 2018 2:18 pm
by srracer
Hi everyone,

I am finally getting my UC300eth-5LPT up and running on my Bridgeport conversion and I'm trying to implement the manual tool change macro I had in Mach 3. For that, I had DROs where I would enter:
X,Y,Z of the tool change position (because it changes depending upon where the vise and work is located)
and
X,Y,Z of the tool touch location (because I have the machine move to a spot wherever that particular work piece is not having the top surface machined off, usually .120" above the surface where I then use the knee and a .120" gauge block to set the 'tool height'.

I have modified the screen and added these fields to the Run screen as textfieldnb fields. I have the constructor setup so that it populates the fields correctly at startup, but I really want the fields to resemble DRO's with the X.XXX format. However, if I type ".1", it just comes in as ".1". If the field is number 20001, is there a macro that runs whenever that field is modified so that I can alter the format and show it as "0.100"?

Or, is there a different way to force string or number formatting in a field?

Also, I see that there are macro functions called "Getfielddouble" or "Setfieldtext" that aren't in any of the macro manuals that I've been able to find, but yet, lot's of people seem to know about them and how to use them. Is there a macro/plugin resource that's hidden away somewhere? The latest one I've found is Robertspark's 1.2105 manual from June 17 and it doesn't even have those.

Similarly, I can't seem to find anything anywhere that describes the difference between field and fieldnb or textfield and textfieldnb. What is the nb?

I'm not new to C/C++ or visual studio, but C# is new to me. I've picked up a c# resource book to learn more, but if my questions are related to standard C# libraries, that would be good to know, too.

Thanks!

Re: Macro Run on field change event? And other questions...

PostPosted: Sat Aug 18, 2018 3:11 pm
by ger21
nb is "no border".

Look in UCCNC\Documentation, both Screenset Functions and Macro Capability. Some things are not documented, though.

You might be able to do what you want with macroloops, but I'm not sure.

Re: Macro Run on field change event? And other questions...

PostPosted: Sat Aug 18, 2018 4:37 pm
by kig23
Hi Srracer,
if you look in Plugin section of the forum you'll find a C++ binding for UCCNC plugin interface, and you can write plugins in C++. If i'm not wrong in the plugin interface there is not handler for field change event. There are handlers for field click and field type events. You can use macroloop or plugin for your task. Here is simple example in C# how to format a double value:

Code: Select all
double test1 = 12.123456789;
double test2 = Convert.ToDouble (test1.ToString("F3"));

and another one using Math
Code: Select all
double test1 = 12.123456789;
double test2 = Math.Round(test1,3);


Hope it's usful for you.

Re: Macro Run on field change event? And other questions...

PostPosted: Sat Aug 18, 2018 6:12 pm
by kig23
Hi,
sorry, I misunderstood you. The examples that i give you don't work for your task. Just put the following code in the macroloop.

Code: Select all
double droValue = Convert.ToDouble (AS3.Getfield(3000));
string droDisplay = droValue.ToString ("F3");
AS3.Setfieldtext (droDisplay, 3000);
AS3.Validatefield(3000);


You have to change the number of the text field. In this case the number of the text field is 3000.

Re: Macro Run on field change event? And other questions...

PostPosted: Sun Aug 19, 2018 12:14 am
by srracer
I completely missed the macroloop section (well, I read it, but it didn't click with me as to what it was for). Now it makes sense.

So, OK, a macroloop is a pretty easy way to run the code I was thinking, but your responses are curious because I would have just used String.Format in the macroloop. Does that mean that standard C# libraries are not available? I was hoping to use something like this:

Code: Select all
string fieldvalue = String.Format("{0:0.000}", AS3.Getfielddouble(20001);
AS3.Setfieldtext(fieldvalue, 20001);
AS3.Validatefield(20001);

Re: Macro Run on field change event? And other questions...

PostPosted: Sun Aug 19, 2018 12:23 am
by srracer
kig23 wrote:Hi,
sorry, I misunderstood you. The examples that i give you don't work for your task. Just put the following code in the macroloop.

Code: Select all
double droValue = Convert.ToDouble (AS3.Getfield(3000));
string droDisplay = droValue.ToString ("F3");
AS3.Setfieldtext (droDisplay, 3000);
AS3.Validatefield(3000);


You have to change the number of the text field. In this case the number of the text field is 3000.


Thank you, Kig - that worked perfectly. I obviously need to do more reading on the different C# methods. Thanks again!!

Re: Macro Run on field change event? And other questions...

PostPosted: Sun Aug 19, 2018 12:26 am
by srracer
srracer wrote:I completely missed the macroloop section (well, I read it, but it didn't click with me as to what it was for). Now it makes sense.

So, OK, a macroloop is a pretty easy way to run the code I was thinking, but your responses are curious because I would have just used String.Format in the macroloop. Does that mean that standard C# libraries are not available? I was hoping to use something like this:

Code: Select all
string fieldvalue = String.Format("{0:0.000}", AS3.Getfielddouble(20001);
AS3.Setfieldtext(fieldvalue, 20001);
AS3.Validatefield(20001);


Sorry to quote myself, but apparently this also works perfectly when I remember to include the close parens. <face palm>

Re: Macro Run on field change event? And other questions...

PostPosted: Sun Aug 19, 2018 7:08 am
by kig23
srracer wrote:Does that mean that standard C# libraries are not available?


You can use in macros the following nemaspaces :
- System
- System.Windows.Forms
- System.Drawing
- System.Threading

Hope this is helpful for you.

Re: Macro Run on field change event? And other questions...

PostPosted: Sun Aug 19, 2018 6:54 pm
by dezsoe
If you have more fields to format then you could check first if the field has a new value. With this you can save CPU for more important tasks.

Code: Select all
double droValue = AS3.Getfielddouble(3000);
if (droValue != lastValue)
{
  AS3.Setfieldtext(droValue.ToString("F3"), 3000);
  AS3.Validatefield(3000);
  lastValue = droValue;
}

#Events

double lastValue = 1234.567800112233;

Re: Macro Run on field change event? And other questions...

PostPosted: Tue Oct 22, 2024 4:17 pm
by sebba
Hello,
I know is an old post but is still related with my issue and I'll reuse it. Hope is OK.

I intend to have a macro which have to run when a field (or fieldnb) is changed by user input.
After changing, the same macro have to save (update, with writekey function) the new entered value in corresponding [UserTextfields].
At start, same field have to be updated by reading it's value from [UserTextfields]. This is done by M99998.
I did a macroloop which compare the stored value with field's value and it's working. If values are different, it run the writekey function and update the value, like I need.

But there is a problem.
When program start, the macroloop seems to be faster than M99998 and read un-updated field's value (which is not yet updated by M99998).
Obviously, this value is different and the macroloop do the writekey function.
Is there any way to make the M99998 to run before the macroloop?

Any advice is appreciate it, thank you!

Best regards,
Seb