Hello Guest it is December 06, 2019, 06:45:02 PM

Author Topic: Plugin or Script to Modify Gcode  (Read 17044 times)

0 Members and 1 Guest are viewing this topic.

Offline BR549

*
  •  6,916 6,916
    • View Profile
Re: Plugin or Script to Modify Gcode
« Reply #10 on: October 18, 2012, 11:03:43 AM »
I checked in MACH CB and I don't find the REPLACE command that is in NORMAL VB. That makes it harder to parse replace strings. I found code that would do a good job BUT it will not run in MACH3 CB.

Still looking, (;-) TP

Offline ger21

*
  • *
  •  6,289 6,289
    • View Profile
    • The CNC Woodworker
Re: Plugin or Script to Modify Gcode
« Reply #11 on: October 18, 2012, 11:44:06 AM »
Quote
I like the ability to jog both Z's independently, and I like the idea of gcode telling the machine exactly what to do

You can still do that with SwapAxis(). I think what you'll need is a set of shortcut keys for the "live" axis, and one for the "inactive" axis.
Getting your CAM software to output g-code for both axis is probably quite a bit trickier.

Quote
That said, there is apparently one more additional benefit to SwapAxis() that hasn't been mentioned yet, although I have not yet begun looking into this issue: Apparently Mach does not let you probe on an A, B, or C axis - that is, you can't use a touch plate to set Z-Zero on the A, B or C Axis (this is according to the user on Joe's forum - again I haven't started looking at this yet

Not sure on this, but I know Terry does 4 axis probing using a rotary A axis.

Quote
Gerry I've already modified your screenset heavily to account for other changes, but it sounds like your touchprobe scripts will need to be modified as well. Having worked on those and given your knowledge of how they work do you think they could be modified to use a different Axis or will SwapAxis() be necessary on those scripts?

I'd have to spend some time looking into it.
When I get my machine done, I'll be doing a new screen for it. Depending on how long it takes me, this may end up being for Mach4, which is supposed to support multiple Z axis natively. But I really don't anticipate jumping to Mach4 until the Tempest trajectory planner is finished.

 I still don't know if the SwapAxis() will be done in the M6 macros, or the macropump. How they're swapped will dictate how the probing needs to work.
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html
Re: Plugin or Script to Modify Gcode
« Reply #12 on: October 18, 2012, 11:52:23 AM »
I checked in MACH CB and I don't find the REPLACE command that is in NORMAL VB. That makes it harder to parse replace strings. I found code that would do a good job BUT it will not run in MACH3 CB.

Still looking, (;-) TP

Thanks I appreciate it. I've begun working on a Macro and have the basics working (I can load the file, read it, and parse it, etc.) but like you noted, there are some String manipulation functions in VB that are not implamented in Mach (including Replace() and also Split() ). Sort of annoying - I'm not sure why they aren't in there, but they aren't. So I'm having to manually write similar functions using InStr(), Mid(), etc. which are included.

You can still do that with SwapAxis(). I think what you'll need is a set of shortcut keys for the "live" axis, and one for the "inactive" axis.
Getting your CAM software to output g-code for both axis is probably quite a bit trickier.
...
Not sure on this, but I know Terry does 4 axis probing using a rotary A axis.
...
I'd have to spend some time looking into it.
When I get my machine done, I'll be doing a new screen for it. Depending on how long it takes me, this may end up being for Mach4, which is supposed to support multiple Z axis natively. But I really don't anticipate jumping to Mach4 until the Tempest trajectory planner is finished.

 I still don't know if the SwapAxis() will be done in the M6 macros, or the macropump. How they're swapped will dictate how the probing needs to work.

Thanks Gerry - Like I said I may end up going back to SwapAxis(). For now, I'm going to stick with a parse of the gcode. As you mentioned previously, this woudl be infinitely easier to use a standalone program, but I'm already far enough along that I can't quit now! It is now a challenge to figure out how to make it work! (OK more like stubbornness!)

Good to hear that Mach4 will support multiple Z axes. I guess we are a still a long way off from that, but glad to hear it is on the horizon.

Thanks again for the help guys - any further comments would be appreciated. I'll post what I come up with once it is done.

Offline BR549

*
  •  6,916 6,916
    • View Profile
Re: Plugin or Script to Modify Gcode
« Reply #13 on: October 18, 2012, 02:18:28 PM »
YOU CAN probe the Z into the abc axis that is a Z probing function. It moves the Z into the material   AND you can PROBE in A  as rotary or linear(The book is WRONG).  The A rotates on its axis as the probe function.

(;-)TP
Re: Plugin or Script to Modify Gcode
« Reply #14 on: October 18, 2012, 04:16:27 PM »
Good to know - thanks! That is the next issue I'm going to have to tackle...
Re: Plugin or Script to Modify Gcode
« Reply #15 on: October 25, 2012, 10:29:24 AM »
OK so I've made a good bit of progress. I completed a working version of the g-code parser for dual z-axis functionality as a VB script and it works very well. Test cuts on my machine worked well also! The big downside is that it is SLOW. The VB-based parser, because Mach uses the Cypress Enable implementation, is cumbersome and I had to use many workarounds and write many of my own string parsing functions that are included in normal VB but not in Enable. But it does work so its a start!

Still, I'm not satisfied and I'd like a more integrated solution anyway, so I've started working on the same type of thing, but it will be a plugin rather than a script. I've made a good bit of progress using the Plugin Wizard. I've completed the basic outline and the plugin is able to open and parse a file on the most basic level. I've also completed the configuration dialog and I'm currently working on integrating the parser with the configuration settings. It has been a while since I wrote anything in C++ so I'm having to re-learn some things. Plus a lot has changes with .Net and VS, managed code, Microsoft's use of pointers, etc. I'm getting there though!

One issue I've run into that I could really use some help on: I can't get Mach to save configuration data to the XML file. I can access the XML functions in the XMLNetProfile class, and I can successfully write to the XML file while Mach is running. However, when I close Mach and it writes the XML file at closing time, my changes to the file are not included. Here is some code I'm using to test that appears in my piNotify() routine:

Code: [Select]
String^ profileNameString = gcnew String(ProfileName);
XMLNetProfile^ multiZConfig = gcnew XMLNetProfile(profileNameString, "MultiZPlugin", true);
multiZConfig->Load();
multiZConfig->WriteString("temp", "TEST");
multiZConfig->Save();

When I load up Mach and access the plugin config window, the XML nodes <MultiZPlugin><temp> are written to the XML file. I can, while Mach is still running, open the XML file and see that they are there. But when I close Mach, the XML file gets overwritten by Mach and those nodes no longer exist.

I must be missing something dumb. Can anyone help me out?

Thanks in advance
Re: Plugin or Script to Modify Gcode
« Reply #16 on: October 31, 2012, 09:01:31 AM »
OK I got the XML bit figured out. It turns out that the XML writing merely needs to be done in the piStopPlug routine is all. This is actually documented in the Mach Plugin Wizard. So I've just about go the plugin finished now. The parsing routine is done and everything is ready to go, except one thing, and I could REALLY use some help with this.

All I want to do is simply tell Mach to load the new gcode file I've created from the parsing. In other words, the plugin writes a new g-code file to disk and i just need the plugin to tell Mach to load the file. I am, of course, able to access all of the Mach variables in MainPlanner and MachView, etc.

However, I am unable to invoke any of the functions such as those in rs274ngc.h. For example, the following code appears in my piNotify() routine:

Code: [Select]
rs274ngc_open(fileNm);
Where fileNm is prperly set as the file name and path (a LPCTSTR). If I compile and build this, it appears to
compile fine, but then I get a linking errors:

Code: [Select]
Error 1 error LNK2028: unresolved token (0A000013) "int __cdecl
rs274ngc_open(char const *)" (?rs274ngc_open@@$$FYAHPBD@Z) referenced in
function __catch$?piNotify@@$$FYAXH@Z$0
C:\Users\usrnm\Desktop\tmp\plgn\Plugin.obj

Error 2 error LNK2019: unresolved external symbol "int __cdecl
rs274ngc_open(char const *)" (?rs274ngc_open@@$$FYAHPBD@Z) referenced in
function __catch$?piNotify@@$$FYAXH@Z$0
C:\Users\usrnm\Desktop\tmp\plgn\Plugin.obj

Error 3 error LNK1120: 2 unresolved externals
C:\Users\usrnm\Desktop\tmp\plgn\Debug\MultiZ.dll

I am about to pull out all of my hairs! I spent most of the day yesterday trying to figure this out but still haven't gotten there. I can't figure out how to make it work...

I also tried using the "scripter" functions available in Mach. I added a reference to Mach3.exe in my project which gave me access to the Mach4 namespace and the IMach4 class. I have tried the following:

Code: [Select]
Mach4::IMach4^ mch = (Mach4::IMach4^) System::Runtime::InteropServices::Marshal::GetActiveObject("Mach4.Document");
Mach4::IMyScriptObject^ scripter = (Mach4::IMyScriptObject^) mch->GetScriptDispatch();

Well that compiles OK but it crashes Mach upon startup. I get "Error found, Art code: 1 - attempt recovery" and "Error Triggered" and Error Stopping Timer" notices upon starting Mach.

All I really want to do is to provide Mach with a string to the file path and just tell mach to load the g-code file! I'd really apprecaite any help anyone can offer - I'm about to lose it!  :-[

Offline BR549

*
  •  6,916 6,916
    • View Profile
Re: Plugin or Script to Modify Gcode
« Reply #17 on: October 31, 2012, 04:44:29 PM »
I can tell you how to do it from a CB script. Just don't know beans about plugin coding. You can use LoadFile() and then have teh OP hit cycle start OR then use RunFile() to auto start the function  or  LoadRUN() to an auto load and start of the file.

Could you post the CB version of your Gcode parser script. I would be interested in learning how you did it.

(;-) TP
« Last Edit: October 31, 2012, 04:46:31 PM by BR549 »
Re: Plugin or Script to Modify Gcode
« Reply #18 on: October 31, 2012, 05:01:18 PM »
Yup that is essentially what I did for the Basic script. I'm attaching it below, but a few notes to anyone who may want to use it:

  • First, please note that this is really in beta form. I've been using it for a week or so and it works well, but I'm still testing and therefore please verify the code it generates prior to running!
  • The script is SLOW. If you have a g-code file of any appreciable size, it will take a while to parse with little indication that it is parsing. I intend to fix this because the current methodoligy is to parse and write the output file line-by-line which is I believe what is really slowing things down. Of course, I'm running day-to-day and a quite old machine so that is probably a lot of the issue also. Anyway, it will be an easy modification to change the writing of the output all at once rather than line-by-line - I just need to spend the time to implement this change
  • There are a lot of settings the user can set (for now these must be manually set by the user by changing the variables in the very first section of the script)
  • There are lots of comments throughout the script so you can see what is going on, but essentially the script works as follows:
    • Call the Mach File -> Open command (DoOEMButton(216))
    • User Opens a file (or cancels) just like any other File Open
    • The script prompts the user whether he wants to parse the file (you can disable this prompt in the settings if you want it to just parse automatically without asking)
    • The script reads the file name and path of the currently open file and then closes the file in Mach
    • The script then opens the file internally (not re-opening the toolpath in Mach yet) using VB commands to read the text of the file
    • The Script Parses the text (change Z movements to A (or whatever axis is chosen) in the proper sections, adds gcode to account for the proper offset of your 2 Z axes, adds additional M codes to turn spindles on and off, etc. All of these can be disabled and set in the settings of the macro
    • Once finished parseing, the script writes the changes to a new g-code file and closes the file
    • Finally, the script tells Mach to open the new file and get it ready for execution.
  • The script also shouldn't be used for projects that use more than 2 tools - the plugin version already handles this but the script version does not. It will work fine for projects that use 1 or 2 tools, but the plugin version handles multiple "sets" of tools - ie tools 1&2 are grouped, 3&4, etc.
  • I use the Mach 2010 screenset (or a modified version of it) so there are some additional items the script does (mainly updating the DRO that shows the name of the currently open file) but it shoudl work with other screensets
  • Please note that the script can't be added in a seperate file (you can't save it in a Macro file). There is a bug in Mach that prevents parsing the file for g-code loading while a macro is running from a file. It works fine as long as you assign the button to execute code and embed the script into the button rather than saving it in a Macro file and invoking the M-code for the file

Here is a video of me testing it out on my machine:

http://www.youtube.com/watch?feature=player_embedded&v=6TLRiieENIY

Hopefully this will be helpful to someone!

Anyway, I'm still stumped on the plugin.  :'( I'd REALLY like to get this to work, but I simply can't figure out how to tell Mach to open my file from the plugin!!!! Anyone out there care to help (please, please, please!)? :D

Offline BR549

*
  •  6,916 6,916
    • View Profile
Re: Plugin or Script to Modify Gcode
« Reply #19 on: October 31, 2012, 05:37:03 PM »
DO you have the Mach Plugin bible "Mach3Mysteries.pdf"  It was written by Art himself. It "seems" all you have to do is call a "macro" and in that macro contain the CB code to Loadfile() or runfile() or loadrun() .

OR NOT(;-)



Thanks, (;-) TP