Hello Guest it is December 15, 2019, 07:52:47 AM

Author Topic: Call function in macros folder from button  (Read 127 times)

0 Members and 1 Guest are viewing this topic.

Call function in macros folder from button
« on: March 09, 2019, 02:30:25 PM »
I have a funtion, setToolDepth, in my macros folder. I was wondering how do I call this function from button?

I am using the blank button in the tool information area. I added the event for "left mouse up", and just put:
Code: [Select]
setToolDepth() In it, but no surprise, it didn't work. How do I make this call. I would like to use the existing function so I don't have the same code in multiple places.
Re: Call function in macros folder from button
« Reply #1 on: March 09, 2019, 03:04:14 PM »
Hi,
the button is a part of the GUI. Its code will be compiled and included in the GUI chunk.

Your macros folder will be compiled and included in the Gcode interpreter chunk.

I memory serves me, you have a m code m1000 do you not? That code calls your setDepth() function?

Then attach this to your button:

local inst=mc.mcGetInstance()
mc.mcCntlGcodeExecuteWait(inst,'m1000')

You may have trouble if the machine is not in 'idle' state and the GUI chunk does not relinquish control.
Try it out.

Craig
My wife left with my best friend...
     and I miss him!
Re: Call function in macros folder from button
« Reply #2 on: March 10, 2019, 02:56:25 PM »
Thanks That worked perfectly!

I'm still learning the nuances of the Mach 4 control structure. But it does make sense.
Re: Call function in macros folder from button
« Reply #3 on: March 10, 2019, 03:00:23 PM »
Hi,

Quote
I'm still learning the nuances of the Mach 4 control structure. But it does make sense.

When we say ' we are trying to learn Lua', its not really correct. The real challenge is learning how the different
parts of Mach interact and the vagaries of Machs API not Lua at all.

Craig
My wife left with my best friend...
     and I miss him!