Hey everyone, I have a mach3 custom macro question.

I am trying to create a macro that I can call through gcode that will automatically load and start a new gcode file.

I my script works perfectly if I run it from the vbscript editor or if I create a button that runs it in mach3. But if I try to type the mcode into mdi it starts to load the gcode but it gets stuck on the "generating toolpath" window.

So if I type in M997, my custom macro, it doesn't work. But if I make it as a button it does load a gcode file and automatically starts my gcode?
This is what my code looks like

LoadFile "gcode.txt"
While IsLoading()
Wend
runfile()


And to give more details on what I am trying to do, because maybe there is another solution.

My machine is a 4x8 router that has automatic sheet loading and material push off for when finished. I am trying to set it up where I have a a custom post processor for when I want the machine to keep cutting the same file on multiple sheets.

My current method is, run the gcode cut file at the end of the file it runs a custom macro that turns off the vacuum table and clears the cut parts on to the conveyor belt. Then I need the machine to load and start a new gcode to sweep the table with the routers dust brush. (That's where my first problem is) after it is swept it will run my auto load macro that grabs a sheet and places it on the spoilboard. That part works fine, but then I need it to load another gcode file and start that cut.

Sorry if that's too much or not enough information ????
Thanks for the help,
Mike