Machsupport Forum

Mach Discussion => Mach SDK plugin questions and answers. => Topic started by: Monotoba on December 26, 2011, 06:10:11 AM

Title: Plugin Access to GCode Window
Post by: Monotoba on December 26, 2011, 06:10:11 AM
Hi, I am new to writing plugins for Mach3 but I have written a few simple wizards. I am looking to move some of my wizards to plugins because debugging in MachScreen is difficult for large wizards. Most of my wizards simple write to the teach file when a user clicks the "Post GCode" button. My first attempt at using the OpenTeachFile() and CloseTeachFile() methods with the VS2008 Plugin wizard failed with unknown function calls. So what I need to know is:

1. Is there a way to write text (gcode) directly to the code window in the main Mach3 screen?
2. Are there functions that can be used to write and load the teach file from a C++ plugin?
3. I have been able to run my gcode right from my plugin but this gives no visual indication of the code execution... If there is no way to load a file into Mach from a plugin like you can from a wizard, then is my best approach simply add a textarea code window to my plugin?

Thanks for your input.

P.S. I have searched for similar post but found nothing and I do apologies if this has been answered before and I simply did not locate the post, or if I have posted this to the wrong area.

Title: Re: Plugin Access to GCode Window
Post by: Steffen_Engel on January 12, 2012, 12:43:39 PM
Hi,

I don't think there is a way to write code to the codebuffer of Mach3.

But you can write to a teachfile as you can do it with your wizards.
Generally spoken, you can do everything in a plugin what you do in a script, and something more  ;)
So I have moved some bigger VBA-Skripts to a plugin just by a VBA to C converter and a little handwork.

Code: [Select]

  scripter.OpenTeachFile("teachtest.nc");

  // some sample code for the teachfile
  scripter.Code("G0X100Y100");
  scripter.Code("G1Z-10");
  scripter.Code("G1Z0");
  scripter.Code("G0X0Y0");

  // finish and load it
  scripter.CloseTeachFile();
  scripter.LoadTeachFile();

just tested this code, but I'm not working with the VS2008 wizard, I'm with VS 2003

regards,

Steffen
Title: Re: Plugin Access to GCode Window
Post by: Monotoba on January 12, 2012, 01:10:40 PM
Thanks,

That is exactly what I needed since I can't go right to the buffer. What VB to C converter are you using?
Title: Re: Plugin Access to GCode Window
Post by: Steffen_Engel on January 12, 2012, 02:01:17 PM
I used BCX (http://www.bcxgurus.com/), this does the most stuff.

String concatenation had to be changed from VBA to C:

Quote
Code "G90G53G0Z" & PositionZ
to
Quote
Code(Format("G90G53G0Z%f", PositionZ));

then indent with my favorite settings:
Quote
indent -ts2 -npsl -bad -bap -bl -bli0 -di10 -bc -lp -l200 <filename>

Then of course the changes to better coding with the methods of C++  ;D

Title: Re: Plugin Access to GCode Window
Post by: poppabear on January 18, 2012, 06:55:50 PM
not trying to argue,

but you can load and run g-code directly from within the plugin, as well as run VB scripts from within a plugin as well (i.e. Mach MAD does this).

Having said the above, though it is MUCH simple to just make "Macros" in VB then run those from within your plugin. You can have your Macros do those things
you want, and then the plugin call them.

scott
Title: Re: Plugin Access to GCode Window
Post by: Steffen_Engel on January 19, 2012, 10:06:58 AM
You're right, but he wants to see the G-Code in the gcode window and the path preview.

This is only possible with loaded G-Code files, as far as I know.

Steffen

Title: Re: Plugin Access to GCode Window
Post by: poppabear on January 19, 2012, 08:01:50 PM
I understand, but what I was saying was you can do just that.......

scott
Title: Re: Plugin Access to GCode Window
Post by: Steffen_Engel on January 19, 2012, 09:26:02 PM
Also correct, you can do that.

But I have no idea, why you should use parts of your code back to this Basic-side, when you know how to code in Plugins.
Maybe to have user-changeable parts, but when there is no need for this, it is strange to go back into vba.

I also do not see, where VBA is simpler for people who already have plugins.

Steffen
Title: Re: Plugin Access to GCode Window
Post by: poppabear on January 20, 2012, 08:11:53 PM
Steffen,

   Yes it is a mystery why he would want to do it that way.........

Scott
Title: Re: Plugin Access to GCode Window
Post by: Steffen_Engel on January 21, 2012, 10:15:38 AM
Huh? I do not understand?

He didn't want anything like that...

Steffen
Title: Re: Plugin Access to GCode Window
Post by: poppabear on January 21, 2012, 10:24:25 AM
???
Title: Re: Plugin Access to GCode Window
Post by: Steffen_Engel on January 21, 2012, 10:34:15 AM
You mentioned to call VBA from Plugins, he didn't

So I have no idea why you mentioned, HE wanted to do something like that

Anyway, Mach3 gives lots of ways to add features by Plugins, VBA and operations.
It's the programmers chance to use any of them.

Steffen
Title: Re: Plugin Access to GCode Window
Post by: poppabear on January 22, 2012, 06:20:42 PM
ohhhhh.... ok, I see where the confusion is, my point was he could use VBA (mach specific subs), to call and load g code into the window, and run it all from the plugin if he wanted........