Machsupport Forum

Mach Discussion => Mach SDK plugin questions and answers. => Topic started by: theminor on October 17, 2012, 10:15:47 AM

Title: Plugin or Script to Modify Gcode
Post by: theminor on October 17, 2012, 10:15:47 AM
I'm trying to determine the best way to handle this. I'm looking to write a fairly simple plugin (or macro script?) that makes modifications to a gcode file whenever it is opened in Mach. Basically the plugin/script would, after a gcode file is opened, parse the gcode file to make certain modifications to the code and then save the changes to the gcode window for execution.

The purpose for wanting to do this is that I've added a second Z axis and second router to my machine. I assigned the second Z axis as the "A" axis in Mach. The second Z axis is at a known offset on the X-Y plane, so I want Mach to parse all loaded gcode files and search for all toolchanges which ask for Tool #2. It will then change all "Z" axis moves to "A" axis moves within that section of Gcode. It will also insert the proper offset code, etc.

I realize I could accomplish the same thing with the swapaxis() command via a macro, but this seems dangerous in that the change can be permanent to the pin designations if mach exits with swapaxis() still active.

I also realize I could simple modify the post-processor in my CAM package to handle all this, but I want a more universal solution.

One way that I might accomplish this would be to create a wizard that brings up a File-Open dialog and thereafter parsed the gcode, saving the result to the "teach file" and posting the gcode. This might work (I think) but I'd prefer to use Mach's actual gcode load routine if possible. It would also be nice if I could save the result to an actual gcode file prior to posting to the gcode window. I'm not sure if any of the above is possible, however.

Ideally, this would be a plugin (I think) with its own plugin options dialog, but I'm having a hard time finding the documentation needed to execute these types of functions. I've watched the tutorial videos and done a fair bit of searching but I can't find information on a plugin's ability to access a loaded gcode file and to modify it.

I would welcome any comment/advice/direction! Thanks in advance.
Title: Re: Plugin or Script to Modify Gcode
Post by: BR549 on October 17, 2012, 01:07:43 PM
Just have MACH3 do an Unswapaxis() on Initiation. That way when you active MACH3 it auto unswapps any swapped drives AND on any Reset it will do the same.

NOW can your routine be done ? Probably but NOT by a mere MORTAL (;-)

(;-) TP

Title: Re: Plugin or Script to Modify Gcode
Post by: theminor on October 17, 2012, 01:15:13 PM
Thanks for the reply! My understanding of SwapAxis(), however, is that it essentially acts the same as actually changing/reversing the ports and pins for the two Axes. You can use ResetAxisSwap() to undo it, but if you close Mach while SwapAxis() is active, it will write the swapped pin designations to the user XML file, making the change permanent. Therefore, when Mach is thereafter loaded, ResetAxisSwap() will not work because the pins are then setup wrong.

That is why I'd prefer not to use SwapAxis() if possible.

Luckily, I'm not mortal (but I'm not immortal either, so I'm not sure what I am)!  :)

The biggest problem I'm having is documentation of what is available in plugins. For macros, there appears to be more documentation, but it is tough to find as much on the plugin side of things!

Any ideas?
Title: Re: Plugin or Script to Modify Gcode
Post by: BR549 on October 17, 2012, 03:53:10 PM
I had to go back and check and YES you are correct it WILL rewrite the XML on close.  The original version (long ago) only kept the swap locally and for the current session of mach3 only.

I'll check around to see IF anyone is up to the task. I assume you want this for old code that was created BEFORE your axis was added?

(;-) TP
Title: Re: Plugin or Script to Modify Gcode
Post by: ger21 on October 17, 2012, 05:32:03 PM
There's an LED to indicate when the axis are swapped. Does it get reset when Mach3 is closed? If not, you can check it's status and determine what you need to do when starting.
Title: Re: Plugin or Script to Modify Gcode
Post by: BR549 on October 17, 2012, 09:32:12 PM
With Mach3 writing the XML changes instead of just keeping the change local I can see where it COULD create a HUGE mess that the Operator would have to KNOW HOW to clean up.

Can't image why it is that way BUT it is what it is. (;-)

I think you could do what is needed with a VB style macro OR  better yet a PLUGIN in C++.   I can see what you need and understand what has to happen but that is about the end of my plugin writing(;-) 

Hopefully one of the heavy coders will show up soon and take a look at the project.

(;-) TP
Title: Re: Plugin or Script to Modify Gcode
Post by: theminor on October 17, 2012, 10:16:09 PM
Thanks everyone for the replies. I've been thinking about it and a plugin woudl definitely be the way to go. however, I'm thinking it would technically be possible using a macro, which would work as follows:

1. Call the Mach File -> Open command (DoOEMButton(216))
2. Read the file name and path of the currently open file
3. Close the file in Mach
4. Open the file using VB commands to read the text of the file
5. Parse the text (change Z movements to A (or whatever axis is chosen) in the proper sections, etc.
6. Write the changes to the text file and close it
7. Have Mach open the file again using DoOEMButton(216) which opens the file ready for execution.

A very roundabout way of going about things but it should be technically possible...
 
Title: Re: Plugin or Script to Modify Gcode
Post by: ger21 on October 17, 2012, 10:33:14 PM
Wouldn't it be easier to write a standalone file converter?

I'm currently building a dual Z axis router, and plan on using SwapAxis() in a macro, calling SawpAxis() based on tool #'s.

If your main concern is closing Mach3 with the axis swapped, there are a coupe things you can do.
1) write a macro to ResetAXisSwap(), give it an M code, and add it to the end of all your g-code. So every time you finish running a program, the SwapAxis() will be reset.
2) add a simple script to the close g-code button to make sure any swaps are reset when you close your g-code file.

These should go a long way towards making it a little safer.

One other thing. I've had my .xml become corrupt a few times now, so I have a backup copy on my desktop. If Mach3 does somehow start with the axis swapped, it's simple to just close it, copy the backup .xml in place, and restart. Not ideal, and maybe not viable at all in your situation, but it's an easy fix.
Title: Re: Plugin or Script to Modify Gcode
Post by: ger21 on October 17, 2012, 11:00:14 PM
Just did a quick test of another idea.
I did some searching, and didn't see a SwapAxis() LED.
So I created a UserLED, and had the macro turn it on when it Swapped the Axis. And turned it off when resetswapaxis() was called.
If you close Mach3 with the axis swapped, they do remain swapped, but the LED remains on.
Have your initialization string swap them back, turn off the led, and pop up a message box telling you to restart Mach3. You should then be good to go.

Kind of a hack, but it seems like it would work fine.
Title: Re: Plugin or Script to Modify Gcode
Post by: theminor on October 18, 2012, 08:52:35 AM
I think SwapAxis() will work fine 99.9% of the time if you take the proper precautions, such as inserting ResetAxisSwap() in a macro that somehow gets run prior to shutting down Mach, and/or at the end of a gcode file, etc.

I've been discussing the issue over on Joe's forum where a user has been running dual Z axes for a year or two now. He uses a modified post-processor in Aspire to handle most of the leg work, but it works very well for him. My only problems with a modified post-processor are that (1) it only works for one tool at a time - when you want to run toolpaths for the second Z, you have to save a new file and then combine the files by had afterward, and (2) it only works with one CAM package unless you write a new post processor or for all your CAM software.

SwapAxis() is a good and simple way to do it and given the ideas to make sure it is reset I don't see much of a chance for problems, especially if you use the LED Gerry is talking about - that is a good idea. But in my opinion, SwapAxis() doesn't really fully capture the essence of what is going on with a dual Z setup. If you use SwapAxis() exclusively, you are really turning your dual Z (two separate axes) into a single Z axis that can by swapped out and offset. I like the ability to jog both Z's independently, and I like the idea of gcode telling the machine exactly what to do rather than tricking the machine into changing pin assignments in the middle of a job. Again, that is really just personal preference when it comes down to it.

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). My inclination is that there must be a way to make this work. However, his solution was simply to use SwapAxis() prior to probing, which solves the problem. He's now able to use the touchplate for both Z axes.

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?
Title: Re: Plugin or Script to Modify Gcode
Post by: BR549 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

Title: Re: Plugin or Script to Modify Gcode
Post by: ger21 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.
Title: Re: Plugin or Script to Modify Gcode
Post by: theminor 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.
Title: Re: Plugin or Script to Modify Gcode
Post by: BR549 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
Title: Re: Plugin or Script to Modify Gcode
Post by: theminor on October 18, 2012, 04:16:27 PM
Good to know - thanks! That is the next issue I'm going to have to tackle...
Title: Re: Plugin or Script to Modify Gcode
Post by: theminor 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
Title: Re: Plugin or Script to Modify Gcode
Post by: theminor 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!  :-[
Title: Re: Plugin or Script to Modify Gcode
Post by: BR549 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
Title: Re: Plugin or Script to Modify Gcode
Post by: theminor 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:


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
Title: Re: Plugin or Script to Modify Gcode
Post by: BR549 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

Title: Re: Plugin or Script to Modify Gcode
Post by: theminor on November 01, 2012, 08:53:40 AM
Yup thanks - I've read through the Bible and it is a great resource. The "macro" you are referencing is the "scripter" bit (i.e. the IMyScriptObject) I reference in my post a few above. The problem is that using the Mach Plugin Wizard, I'm having a very hard time implementing that object - it compiles fine, but crashes Mach upon startup. Very frustrating, but I continue to try and try to get it working!
Title: Re: Plugin or Script to Modify Gcode
Post by: theminor on November 03, 2012, 02:57:37 PM
Well after days of trying to get this working, I decided to allow the VB script that calls the plugin to handle the file-open operation. So it now works. Not the most elegant solution but at least it works. I need to do some testing but I should be in a position to post the plugin pretty soon.
Title: Re: Plugin or Script to Modify Gcode
Post by: theminor on November 11, 2012, 02:28:19 PM
I wanted to go ahead and post this BETA version of my Dual-Z plugin. Like the script, this plugin works primarily by parsing a loaded g-code file and (among other things) assigning the "Z" axis moves under the tool number(s) of your choosing to another axis of your choosing. For example, changing all "even numbered" tools from Z axis movements to A axis movements (again the particular tool numbers and axis letters can be modified). It does a lot of other things too, such as adding the proper offset from one Z axis to the other, etc. The plugin version is much more robust than the script and also has a built-in configuration window. It is also MUCH faster and can parse files nearly instantly whereas the script took a long time for big files.

I've done some testing on my own G-Code files, but that is all the testing this has undergone, so anyone who uses this, please send feedback. Until you are confident that it works properly with your setup, I'd recommend air-cutting or at least visually inspecting the generated g-code prior to real cutting.

See the readme for more important information, but be aware that this plugin requires the .NET Framework 3.5 and you'll also need to modify the File-Open button script in order to call the plugin. Pretty simple to do and full instructions are in the readme file (which is copied below).

Hopefully someone will find this useful!

ReadMe file is copied below:

Code: [Select]
Multi-Z File-Open Macro/Script by theminor
Version 0.6

This Plugin is designed to replace the standard File -> Open button in Mach. The plugin works by presenting the a File-Open dialog for the user to open a gcode file. Upon selecting a file, the user is prompted if he wants the file to be parsed (the prompt can be turned-off via the settings such that the parsing happens automatically without prompting). If the file is to be parsed, the script will search for all toolchange operations which select a tool number set by the user in the settings (for example all "even" numbered tools, all "odd" numbered tools, or a specific tool number only). If an applicable toolchange is found, all "Z" axis moves in that toolchange section will be modified to axis movements on the A, B, or C Axis (set by the user) for the user's Secondary Z axis. A "G52" offset command  may also be inserted in these sections to accont for the offset (set by user) of the Second Z axis from the First Z axis. Additional codes and options may also be inserted/set, such as M codes that turn the spindles on and off as appropriate in these sections. Once the file is parsed, the file is saved under a new file name with a suffix set by the user. The modified file is then opened in Mach, ready for execution as with any other gcode file. For additional help with this plugin, see the "tooltips" for each option in the configuration page of the plugin.

To install, copy the MultiZ.dll file to your Mach3\PlugIns directory. Load Mach and enable the plugin via the Config -> Config Plugins menu. Click OK and restart Mach. Upon restart, configure the plugin via the Plugin Control -> MultiZ menu.

The plugin requires the Microsoft .NET Framework Version 3.5 to be installed. This can be downloaded for free here: http://www.microsoft.com/en-us/download/details.aspx?id=22  --  If you get an error upon starting Mach, it is likely because you do not have the .NET 3.5 Framework installed.

Finally, to actually invoke the plugin, you will need to modify the button script of the button in Mach that you want to call the plugin to open the G-Code file. My preference is to change Mach's "Open G-Code" button, but any button can be used. The script should be modified with the following code:


Declare Function CallDLLFunc Lib "MultiZ" () As String
Dim file As String
file = CallDLLFunc()
If file <> "" Then
LoadFile(file)
' SetUserLabel (2, GetLoadedGCodeFileName()) ' Uncomment this line (remove the single-quote at the beginning of the line) to Set the Use Label 2 to the file name that is loaded (useful if you use the 2010 Screenset or similar screenset)
End If 






This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. Please see:
http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_US
This software is provided "as-is," without any express or implied warranty. In no event shall the author be held liable for any
damages arising from the use of this software.
Title: Re: Plugin or Script to Modify Gcode
Post by: kareed on May 24, 2013, 11:58:48 AM
Hi theminor,
Were you able to figure out how to get by the error you were getting in you earlier post

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

I am getting the same thing and was hoping I could get some help.  I am using the mach3 wizard and vs 2008  also.
Thanks
Title: Re: Plugin or Script to Modify Gcode
Post by: theminor on May 24, 2013, 01:07:21 PM
Its been a while so I'm not 100% sure, but I believe that error was due to no being able to invoke any of the functions such as those in rs274ngc.h - for example, rs274ngc_open(fileName)

I ended up using the workaround described in this thread...
Title: Re: Plugin or Script to Modify Gcode
Post by: danilom on May 30, 2013, 11:07:02 AM
Theminor , how did you alter the second Z axis zeroing routine. It won't work for me if I probe and try GetVar(2004) which is my B axis or second Z. Its said that probing won't work if a rotational axis is moving (abc) or there is no movement in XYZ axis

I am currently using a trick doing a swapaxis with Z and writing the value back to B axis DRO in the end
Title: Re: Plugin or Script to Modify Gcode
Post by: kareed on May 31, 2013, 02:35:23 PM
Hi Theminor,
I received a response from someone else and I was informed that the function rs274ngc_open is not available to a plugin.  I guess this explains the error. 

I like you solution and I am trying to go something similar (modifying the gcode).  I have a plugin that does what I want, though I would just like to have it function similarly to yours ie. click the load gcode button and then access the modifying function.  I am however new to c++ and was hoping I could get some help from you in what you put in the plugin to allow access from a script.  If possible could post you what you did.  I am using vs2008 which I believe you were too. 

Thanks for the help.
Title: Re: Plugin or Script to Modify Gcode
Post by: theminor on May 31, 2013, 02:45:31 PM
Theminor , how did you alter the second Z axis zeroing routine. It won't work for me if I probe and try GetVar(2004) which is my B axis or second Z. Its said that probing won't work if a rotational axis is moving (abc) or there is no movement in XYZ axis

I am currently using a trick doing a swapaxis with Z and writing the value back to B axis DRO in the end

I believe swapaxis is the only workable solution. I haven't done a lot of experimenting with probing, but I remember reading elsewhere that it would not work the same. I think you could do a custom script or plugin that constantly checked the status of the probe input while moving the additional axis, but it could be a lot more complex than the regular z routine... Am I understanding your question correctly?

Hi Theminor,
I received a response from someone else and I was informed that the function rs274ngc_open is not available to a plugin.  I guess this explains the error. 

I like you solution and I am trying to go something similar (modifying the gcode).  I have a plugin that does what I want, though I would just like to have it function similarly to yours ie. click the load gcode button and then access the modifying function.  I am however new to c++ and was hoping I could get some help from you in what you put in the plugin to allow access from a script.  If possible could post you what you did.  I am using vs2008 which I believe you were too. 

Thanks for the help.


kareed - check the readme I posted a few posts up - that pretty much explains the workaround I used. Basically you have to use the VB script macro to interact with the plugin. Definitely a hack. Annoying that you can't do it directly in the plugin... Let me know if you need more info such as how to read the call from CallDLLFunc() on the C++ side...
Title: Re: Plugin or Script to Modify Gcode
Post by: kareed on May 31, 2013, 03:22:21 PM
Hi Theminor,
Actually the part I am most interested in is the c++ part.  I don't know what I need to do to the c++ plugin files to allow vb access to the functions.  I have all the c++ functions written and working for what I want to do which is to convert the gcode and save it to a new file.  I just want it to return a string or filename to VB.  Essentially your solution I believe will work great using the same vb script for the button and this is where I am stuck.
Title: Re: Plugin or Script to Modify Gcode
Post by: theminor on May 31, 2013, 03:50:19 PM
Hi Theminor,
Actually the part I am most interested in is the c++ part.  I don't know what I need to do to the c++ plugin files to allow vb access to the functions.  I have all the c++ functions written and working for what I want to do which is to convert the gcode and save it to a new file.  I just want it to return a string or filename to VB.  Essentially your solution I believe will work great using the same vb script for the button and this is where I am stuck.

This should get you started. This code is in my MachDevice.cpp file:

Code: [Select]
typedef WCHAR OLECHAR;
typedef OLECHAR* BSTR;
typedef BSTR* LPBSTR;

extern "C" __declspec(dllexport) BSTR CallDLLFunc()
{
char *fName = mZGo();
return SysAllocStringByteLen(fName, strlen(fName));
}

Let me know if you need anything else - it has been a while since I've worked on this project so I'm having to remember what is what! I believe that this is the actual function that gets called from the VB Script. The funciton returns the final file to be opened by Mach.

Title: Re: Plugin or Script to Modify Gcode
Post by: kareed on June 01, 2013, 01:33:12 AM
Hi Theminor,
Thanks for the help.  I think I have it working.  One line I needed to add to MachDevice.cpp was this

#include <ole2.h>

Thanks again it was really appreciated.
Title: Re: Plugin or Script to Modify Gcode
Post by: poppabear on June 02, 2013, 06:04:55 PM
on the BTSR's, make sure you destroy them after use, otherwise they make a memory leak.

scott