#Events: a little surprise from UCCNC

Here is where you can drop off Examples of WORKING macros,plugins,Gcode programs , macro Wizards etc.
Please give a brief description of what it is and how it works.

#Events: a little surprise from UCCNC

Postby dezsoe » Mon May 29, 2017 11:00 am

Over the development of UCCNC, first came the #Events tag in macros. This was made for putting special code in macros to handle forms events or other functions/subroutines. An other development was about the macro compilation. In the past every time a macro was called, it was first compiled. It was very slow. Now if Precompile switch is on the macros are compiled on program startup, or if not, they are compiled on first run. Of course, if a macro is changed, it will be compiled again.

These two developments have a little but very useful side-effect: we can use static variables after the #Events tag. These variables store their values until the macro is recompiled or UCCNC exits. A small example:

Code: Select all
AS3.Additemtolistbeginning("Value: " + value, 2);


static int value = 0;

Running this macro more times you can see in the status window the increasing value.

Now we have unlimited possibilities. :) Let's make a tri-state button: every press executes the next function in cycle:

Code: Select all
switch (state)
  case 1:
    AS3.Additemtolistbeginning("First state", 2);
  case 2:
    AS3.Additemtolistbeginning("Second state", 2);
  case 3:
    AS3.Additemtolistbeginning("Third state", 2);
    state = 1;


static int state = 1;

In the past you had to use #variables or - as the worst way - you could write values to the profile and read back. The first was only for numeric values and could interfere with the running g-code, the second is slow and messes up the profile file.
Posts: 335
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: #Events: a little surprise from UCCNC

Postby Vmax549 » Tue May 30, 2017 2:35 pm

(;-) ;) Thank You Dezsoe that was an interesting surprise.

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


Who is online

Users browsing this forum: No registered users and 1 guest