Hello Guest it is December 10, 2019, 03:44:47 AM

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

0 Members and 1 Guest are viewing this topic.

Re: Plugin or Script to Modify Gcode
« Reply #20 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!
Re: Plugin or Script to Modify Gcode
« Reply #21 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.
Re: Plugin or Script to Modify Gcode
« Reply #22 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.
Re: Plugin or Script to Modify Gcode
« Reply #23 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
Re: Plugin or Script to Modify Gcode
« Reply #24 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...
Re: Plugin or Script to Modify Gcode
« Reply #25 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
Re: Plugin or Script to Modify Gcode
« Reply #26 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.
Re: Plugin or Script to Modify Gcode
« Reply #27 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...
Re: Plugin or Script to Modify Gcode
« Reply #28 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.
Re: Plugin or Script to Modify Gcode
« Reply #29 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.