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

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

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

Postby srracer » Sat Aug 18, 2018 2:18 pm

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!
srracer
 
Posts: 4
Joined: Sat Aug 18, 2018 1:59 pm

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

Postby ger21 » Sat Aug 18, 2018 3:11 pm

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.
Gerry
UCCNC 2017 Screenset - http://www.thecncwoodworker.com/2017.html
ger21
 
Posts: 1111
Joined: Sat Sep 03, 2016 2:17 am

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

Postby kig23 » Sat Aug 18, 2018 4:37 pm

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.
kig23
 
Posts: 104
Joined: Sat Mar 31, 2018 6:58 am
Location: Italy

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

Postby kig23 » Sat Aug 18, 2018 6:12 pm

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.
kig23
 
Posts: 104
Joined: Sat Mar 31, 2018 6:58 am
Location: Italy

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

Postby Vmax549 » Sat Aug 18, 2018 6:52 pm

That I am aware of there is NO decimal formating for dros OTHER than positional xyzabc dros. Hopefully we will get it some day.

You could use teh max and min fields to set teh decimal format

Max ( 99.9999 )
Min (-99.9999 )

The four decimal points in teh values could be used to set teh decimal format for that field.

But that is something for UCCNC to think about.

(;-) TP
Vmax549
 
Posts: 1184
Joined: Sun Nov 22, 2015 3:25 am
Location: USA

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

Postby srracer » Sun Aug 19, 2018 12:14 am

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);
srracer
 
Posts: 4
Joined: Sat Aug 18, 2018 1:59 pm

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

Postby srracer » Sun Aug 19, 2018 12:23 am

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!!
srracer
 
Posts: 4
Joined: Sat Aug 18, 2018 1:59 pm

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

Postby srracer » Sun Aug 19, 2018 12:26 am

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>
srracer
 
Posts: 4
Joined: Sat Aug 18, 2018 1:59 pm

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

Postby kig23 » Sun Aug 19, 2018 7:08 am

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.
kig23
 
Posts: 104
Joined: Sat Mar 31, 2018 6:58 am
Location: Italy

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

Postby dezsoe » Sun Aug 19, 2018 6:54 pm

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;
dezsoe
 
Posts: 513
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary


Return to Macros

Who is online

Users browsing this forum: No registered users and 3 guests