Page 1 of 1

My first Macro - need a second set of eyes.

PostPosted: Tue May 27, 2025 4:57 am
by kgoods
I'm using Gerry's 2022 screenset.

I recently added a camera to set X and Y on my CNC router. Helps index the rotary as well.

I wrote this simple macro to move the spindle to the camera position and then set the X and Y to zero. My plan is to create a button on the Camera page to call the macro. If I understand correctly all I need to do is to name the button the same as the macro number for the two to be associated, if this is not correct please let me know.

My intentions.... move to Z-.100 in machine coordinates to insure clearance no matter what tool I have in the spindle. Then move X and Y relatively to the camera position, then set x and y to zero in the current work coordinates. To finish up I set the modals to my most common usage.

I know it's simple but my first one and just wanted to get another set of eyes in case I missed something. Thanks in advance for any input!

Code: Select all
//Just in case......
exec.Stopspin(); // Stop Spindle

exec.Code("G53 G0 Z-0.100"); // Move Z to .100 under machine home
while(exec.IsMoving()){}

exec.Code("G91 G0 X-2.677 Y2.106"); // Move spindle to camera position
while(exec.IsMoving()){}

// Get Current Offset and set X and Y to zero in that offset
   bool G54YN = AS3.Getbuttonstate(118); //G54
   bool G55YN = AS3.Getbuttonstate(119); //G55
   bool G56YN = AS3.Getbuttonstate(120); //G56
   bool G57YN = AS3.Getbuttonstate(121); //G57
   bool G58YN = AS3.Getbuttonstate(122); //G58
   bool G59YN = AS3.Getbuttonstate(123); //G59

   if (G54YN)
      {
      AS3.Setfield(0, 133); // Set G54 X axis new zeroed position
      AS3.Validatefield(133);
      AS3.Setfield(0, 134); // Set G54 Y axis new zeroed position
      AS3.Validatefield(134);
      }
   if (G55YN)
      {
      AS3.Setfield(0, 139); // Set G55 X axis new zeroed position
      AS3.Validatefield(139);
      AS3.Setfield(0, 140); // Set G55 Y axis new zeroed position
      AS3.Validatefield(140);
      }
   if (G56YN)
      {
      AS3.Setfield(0, 145); // Set G56 X axis new zeroed position
      AS3.Validatefield(145);
      AS3.Setfield(0, 146); // Set G56 Y axis new zeroed position
      AS3.Validatefield(146);
      }
   if (G57YN)
      {
      AS3.Setfield(0, 151); // Set G57 X axis new zeroed position
      AS3.Validatefield(151);
      AS3.Setfield(0, 152); // Set G57 Y axis new zeroed position
      AS3.Validatefield(152);
      }
   if (G58YN)
      {
      AS3.Setfield(0, 157); // Set G58 X axis new zeroed position
      AS3.Validatefield(157);
      AS3.Setfield(0, 158); // Set G58 Y axis new zeroed position
      AS3.Validatefield(158);
      }
   if (G59YN)
      {
      AS3.Setfield(0, 163); // Set G59 X axis new zeroed position
      AS3.Validatefield(163);
      AS3.Setfield(0, 164); // Set G59 Y axis new zeroed position
      AS3.Validatefield(164);
      }

//Leave modals in safe settings
   exec.Code("G90");
   exec.Code("G1");

Re: My first Macro - need a second set of eyes.

PostPosted: Tue May 27, 2025 3:55 pm
by ger21
If you already know the camera coordinates, then there's no reason to move the X and Y axis. You just set the offsets equal to the camera's coordinates.

Re: My first Macro - need a second set of eyes.

PostPosted: Tue May 27, 2025 8:13 pm
by kgoods
ger21 wrote:If you already know the camera coordinates, then there's no reason to move the X and Y axis. You just set the offsets equal to the camera's coordinates.


Of course, makes sense, was stuck thinking about it from the way I did it manually. Appreciate the input.

On another note, does your 2022 screenset work with 1.2118? I've had the UCR201 movement issue since I've had it and would like to get rid of it if possible. But I don't want to lose your screenset. If 2022 is not compatible with 1.2118 are you planning a new screenset any time in the near future? If so, I'd be happy to purchase the new one.

Thanks!

Re: My first Macro - need a second set of eyes.

PostPosted: Wed May 28, 2025 10:36 am
by ger21
No, it's not compatible, due to multiple new features in the newer versions.
I am planning a new version, but it won't be any time soon.

Re: My first Macro - need a second set of eyes.

PostPosted: Thu May 29, 2025 12:03 am
by kgoods
OK thanks, totally understandable. I'll keep checking back every once in a while.