Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: Jeff_Birt on May 07, 2014, 07:55:30 AM

Title: Load GCode from fixed directory - for TP
Post by: Jeff_Birt on May 07, 2014, 07:55:30 AM
TP wanted to be able to have a fixed directory that is opened when you click the 'Load GCode' button. Well with Mach4 you can do that and it is not too hard. Open the screen editor and click on the 'Open GCode' button and set the 'Left Down Action' to blank and then paste this script in for the 'Clicked Script'.

Code: [Select]
local inst = mc.mcGetInstance();
local myGCodePath = "C:/Mach3/GCode";

local fileDialog = wx.wxFileDialog(wx.NULL, "Open file", myGCodePath,
        "", "All files(*)|*", wx.wxFD_DEFAULT_STYLE);

local result = false;

  if fileDialog:ShowModal() == wx.wxID_OK then
    local fileName = fileDialog:GetPath();

    result = mc.mcCntlLoadGcodeFile(inst, fileName);
    if not result then
        wx.wxMessageBox("Sorry, I could not open file.");
    end
  end
Title: Re: Load GCode from fixed directory - for TP
Post by: Ya-Nvr-No on May 07, 2014, 08:08:07 AM
Nice job Jeff,

if you have the Left up option field set to "Gcode Load"
Like that it can open both the Mach4 gcode folder and the Mach3 gcode folder

Thanks for sharing/posting
Title: Re: Load GCode from fixed directory - for TP
Post by: Jeff_Birt on May 07, 2014, 08:14:33 AM
The directory path inset it to was just an example, i.e. someplace that was not in the Mach4 directory. It would be set to what ever is the 'standard' gcode folder on your controllers. Terry wanted to make it simple so it always opened the same directory each time to lessen the likelihood of operator error.
Title: Re: Load GCode from fixed directory - for TP
Post by: Ya-Nvr-No on May 07, 2014, 08:30:39 AM
Sorry, I followed that, just was letting others know it can do double duty. Now it makes me wonder if you can open several more at the same time? Like plugging in a usb thumb drive and accessing it at the same time. Or looking on a network for remote drives.

Thanks again, this is the kind of things that drive a communities interest in sharing and feeling like anything is possible.
Title: Re: Load GCode from fixed directory - for TP
Post by: Jeff_Birt on May 07, 2014, 09:52:27 AM
If you want to restrict the file types that someone can see you just need to set the file filter string as shown below. Note that the first type in the filter string gets shown as default. This stops someone from browsing all but the file extensions you include in the filter, it does not prevent them from typing in a different filenale.ext though. If you wanted to be double sure that only files of a certain type are opened, say if you had some sort of custom machine, then you could use something like 'string.gmatch' to find the extension type and compare it to your allowed types.

I build a controller for a specialized machine that currently runs with a custom screen set on Mach3. For a machine like this being able to lock down what could be loaded and where it can be loaded from would be a good thing.

Code: [Select]
local inst = mc.mcGetInstance();
local myGCodePath = "C:/Mach3/GCode";

local fileDialog = wx.wxFileDialog(wx.NULL, "Open file", myGCodePath,
        "", "NC files (*.nc)|*.nc|TAP files (*.tap)|*.tap", wx.wxFD_DEFAULT_STYLE);

local result = false;
  if fileDialog:ShowModal() == wx.wxID_OK then
    local fileName = fileDialog:GetPath();

    result = mc.mcCntlLoadGcodeFile(inst, fileName);
    if not result then
        wx.wxMessageBox("Sorry, I could not open file.");
    end
  end
Title: Re: Load GCode from fixed directory - for TP
Post by: BR549 on May 07, 2014, 10:36:30 AM
THANK YOU Jeff, THAT is just the Function we need TO help keep the Monkeys working.

NOW IF you are adventurous I have a Mach3 function that looks at the directory and VIEWS pictures of parts(*.bmp) and you select the picture of the part and it loads the Gcode file associated with it.

SheetCam creates the images of the JOB and stores them in a directory and teh NAMES always matches the Gcode it posts. I put it together from the Mach3 CB manual examples BUT I cannot find any code examples for this in LUA.

(;-)TP
Title: Re: Load GCode from fixed directory - for TP
Post by: Ya-Nvr-No on May 07, 2014, 10:51:26 AM
"", "NC files (*.nc)|*.nc|TAP files (*.tap)|*.tap", wx.wxFD_DEFAULT_STYLE);

I don't find it reading any other than the nc files
Title: Re: Load GCode from fixed directory - for TP
Post by: Jeff_Birt on May 07, 2014, 11:04:54 AM
Look in the lower right of the file open dialog, there is a drop down box that lets you select the file type :) I'm not sure if it can show all allowed types at once or not.

I have spent way too much time on this, mainly trying to figure out Lua's string manipulation functions, but did manage to add a secondary file type check.

TP - You can add a secondary dialog to the bottom of the standard File Open dialog. This would be a good way to show an image association to the file. Another way to do this is to write an extension to the OS that tells the OS how to create/show a thumbnail of the file but that is much more effort.

Code: [Select]
local inst = mc.mcGetInstance();
local myGCodePath = "C:/Mach3/GCode";

local fileDialog = wx.wxFileDialog(wx.NULL, "Open file", myGCodePath,
        "", "NC files (*.nc)|*.nc|TAP files (*.tap)|*.tap",

wx.wxFD_DEFAULT_STYLE);

  if fileDialog:ShowModal() == wx.wxID_OK then

    local fileName = string.reverse(fileDialog:GetFilename());
    local pos = string.find(fileName, "%.");
    local fileExt = string.reverse(string.sub(fileName, 1, pos-1));

    if fileExt == "tap" or fileExt == "nc" then
        local filePath = fileDialog:GetPath();
        local result = mc.mcCntlLoadGcodeFile(inst, filePath);
        if not result then
            wx.wxMessageBox("Sorry, I could not open file.");
        end
    else
        local message = string.format("%s is wrong file type",

fileExt);
        wx.wxMessageBox(message);
    end

  end
Title: Re: Load GCode from fixed directory - for TP
Post by: Brian Barker on May 07, 2014, 11:21:33 AM
Please will someone say it.. WxLua was the correct scripting environment! Look at what has been done and we have done NO docs so far...  I can't wait to see where this goes...

After all the bitching about it not being VB, This is way better then VB LOL
Thanks
Brian
Title: Re: Load GCode from fixed directory - for TP
Post by: BR549 on May 07, 2014, 11:32:08 AM
NO conditional Gcode and macroB was the correct decision(;-).

Lua is good for system programming as LONG as you can master it. I dought that the average Joe chip sling will be able to use much of it.

The idea is to have a complete CNC control out the door ready to go for a normal CNC machine application.  Dedicated controllers work WELL for a reason(;-)

That said being able to create a custom motion control application is NOT a bad thing as LONG as that idea is NOT the main theme of developement.

Mach3 was dramatically hampered by that approach in many areas. At time critcal core things were ignored just to work on fantasy functions.



Been there done that one, (;-) TP
Title: Re: Load GCode from fixed directory - for TP
Post by: Ya-Nvr-No on May 07, 2014, 11:35:19 AM
Did get this work

Code: [Select]
local inst = mc.mcGetInstance();
local myGCodePath = "C:/Mach3/GCode";

local fileDialog = wx.wxFileDialog(wx.NULL, "Open file", myGCodePath,
        "", "All files(*)|*", wx.wxFD_DEFAULT_STYLE);

  if fileDialog:ShowModal() == wx.wxID_OK then

    local fileName = string.reverse(fileDialog:GetFilename());
    local pos = string.find(fileName, "%.");
    local fileExt = string.reverse(string.sub(fileName, 1, pos-1));

    if fileExt == "tap" or fileExt == "nc" or fileExt == "txt" then
        local filePath = fileDialog:GetPath();
        local result = mc.mcCntlLoadGcodeFile(inst, filePath);
        if not result then
            wx.wxMessageBox("Sorry, I could not open file.");
        end
    else
        local message = string.format("%s is wrong file type",

fileExt);
        wx.wxMessageBox(message);
    end
  end

Just does not like this, though I do like your added check, thanks

"", "NC files (*.nc)|*.nc|TAP files (*.tap)|*.tap", wx.wxFD_DEFAULT_STYLE);

Jury still out on the Lua until we see some docs,  :o
Were liking most of it. Kind of a Love Hate thing
Different woman, new issues to deal with.
Title: Re: Load GCode from fixed directory - for TP
Post by: Jeff_Birt on May 07, 2014, 11:42:28 AM
What do you mean, "does not like this"?

Jeff
Title: Re: Load GCode from fixed directory - for TP
Post by: Brian Barker on May 07, 2014, 11:46:33 AM
But this woman can do things that the old one couldn't do.. I think Chris Rock did a skit on that...

Anyhow I don't think we are going to make a WX Lua programming manual, it will be more programming by examples and if someone is smart they can go look at WX and Lua and get it to do more. Way to much to document!
Title: Re: Load GCode from fixed directory - for TP
Post by: Jeff_Birt on May 07, 2014, 11:50:39 AM
The only tricky bits I have found are remembering to put 'wx.' before things and learning the specifics of how Lua does things, like strings, or the not equals operator '~=', etc. It is not hard, just a learning curve. Some things like the format of the path, i.e. using '/' as un Unix convention instead of '\' as in Windows through me for a loop only because I could not find any documentation or samples of what the format was supposed to be.
Title: Re: Load GCode from fixed directory - for TP
Post by: BR549 on May 07, 2014, 11:51:57 AM
NO Mach4/Lua programming manual ???

The old Mach3/Cypress Basic Manual was a GREAT asset in dealling with Mach3 macros.

With you setting up all the custom functions and STUFF for LUA I find little to NO example of this type programming on the WEB. MOST of what I find is for creating GAMING programs. THE REST of the references  ASSUMES that you are already a Cracker Jack C programmer and FULLY understand the process.


(;-) TP
Title: Re: Load GCode from fixed directory - for TP
Post by: Ya-Nvr-No on May 07, 2014, 11:53:41 AM
What do you mean, "does not like this"?
that it only displayed the nc files and not the tap files
Title: Re: Load GCode from fixed directory - for TP
Post by: Jeff_Birt on May 07, 2014, 12:25:58 PM
Look in the lower right corner of the dialog....

(http://www.soigeneris.com/images/forumpics/File_Type.png)
Title: Re: Load GCode from fixed directory - for TP
Post by: Ya-Nvr-No on May 07, 2014, 12:50:57 PM
Oh ya I see now
    "", "TXT files (*.txt)|*.txt|NC files (*.nc)|*.nc|TAP files (*.tap)|*.tap", wx.wxFD_DEFAULT_STYLE);

    This is what I was expecting when they displayed that they all showed,
    I keep different extensions in different folders.
    And just expected to see them all and not have to change the pull down. My Bad
    Thanks always good to have visual aids.
   
    "", "GCode files (*.txt;*.nc;*.tap)|*.txt;*.nc;*.tap", wx.wxFD_DEFAULT_STYLE);
Title: Re: Load GCode from fixed directory - for TP
Post by: Jeff_Birt on May 07, 2014, 01:11:48 PM
You have the idea. You can also include all supported types as you have and also list them separately which can help you sort out a lot of files.

Code: [Select]
local fileDialog = wx.wxFileDialog(wx.NULL, "Open file", myGCodePath,
        "", "All CNC (*.nc; *.tap)|*nc;*tap|NC files (*.nc)|*.nc|TAP files (*.tap)|*.tap",
        wx.wxFD_DEFAULT_STYLE);
Title: Re: Load GCode from fixed directory - for TP
Post by: Ya-Nvr-No on May 07, 2014, 06:30:55 PM
Should be a cleaner way to do this, but it does work, thanks Jeff
just hit cancel if you don't want that particular folder goes to the next one.
handles USB and networks fine

Code: [Select]
local inst = mc.mcGetInstance();

local myGCodePath = "C:/";
local Path1 = "C:/Mach3/GCode";
local Path2 = "C:/Mach4/Test GCodes";
local Path3 = "F:/";
local Path4 = "//LIGHT-TABLE/GCode";
local i;

for i=1 , 4 do

if ( i==1 ) then
    myGCodePath = Path1;
end
if (i==2) then
    myGCodePath = Path2;
end
if (i==3) then
    myGCodePath = Path3;
end
if (i==4) then
    myGCodePath = Path4;
end

local fileDialog = wx.wxFileDialog(wx.NULL, "Open file", myGCodePath,
    "", "GCode files (*.txt;*.nc;*.tap)|*.txt;*.nc;*.tap|TXT files (*.txt)|*.txt|NC files (*.nc)|*.nc|TAP files (*.tap)|*.tap", wx.wxFD_DEFAULT_STYLE);

  if fileDialog:ShowModal() == wx.wxID_OK then
    local fileName = string.reverse(fileDialog:GetFilename());
    local pos = string.find(fileName, "%.");
    local fileExt = string.reverse(string.sub(fileName, 1, pos-1));
    if fileExt == "tap" or fileExt == "nc" or fileExt == "txt" then
        local filePath = fileDialog:GetPath();
        local result = mc.mcCntlLoadGcodeFile(inst, filePath);
        if not result then
            wx.wxMessageBox("Sorry, I could not open file.");
        end
    else
        local message = string.format("%s is wrong file type", fileExt);
        wx.wxMessageBox(message);
    end
  end
end
Title: Re: Load GCode from fixed directory - for TP
Post by: BR549 on May 07, 2014, 06:39:53 PM
Craig I am not sure all that will fit in that tiny button.

(;-) TP
Title: Re: Load GCode from fixed directory - for TP
Post by: Ya-Nvr-No on May 07, 2014, 06:43:03 PM
That's why I made my bigger,  ;D
Title: Re: Load GCode from fixed directory - for TP
Post by: BR549 on May 07, 2014, 07:02:42 PM
HEY Craig interested in taking a wack at a bar code scanner routine for loading Gcode files. Brian had one for Mach3 as a plugin.

Just a thought, (;-) TP
Title: Re: Load GCode from fixed directory - for TP
Post by: Ya-Nvr-No on May 07, 2014, 07:10:51 PM
Sorry, kind of busy building two machines right now.
Title: Re: Load GCode from fixed directory - for TP
Post by: ger21 on May 07, 2014, 07:34:37 PM
Sorry, kind of busy building two machines right now.

Yeah, we can tell. ;)
Title: Re: Load GCode from fixed directory - for TP
Post by: Ya-Nvr-No on May 08, 2014, 06:30:51 AM
Not that I have to explain, but for the past couple of weeks I have been nursing an injury I sustained working on one of them. So I've had plenty of butt time. Just looked like I have nothing else to do,  ;D
Starting to get back in shape but not quite there yet. So this new programming challenge was great timing.
Hell to get Old.
Title: Re: Load GCode from fixed directory - for TP
Post by: Overloaded on May 08, 2014, 09:03:55 AM
Best wishes regarding your recovery Craig.
I, for one, am very appreciative of your help and contributions.
Guys like me couldn't survive here without guys like you.
Get well quick, but hope you can still reserve a little "butt" time for us.

Regards,
Russ
Title: Re: Load GCode from fixed directory - for TP
Post by: Ya-Nvr-No on May 08, 2014, 09:14:52 AM
Thanks Russ, though not sure the rhoids can take much more  :o
I got to get outside and enjoy the weather too.
Damn long winter.
Title: Re: Load GCode from fixed directory - for TP
Post by: RICH on May 09, 2014, 07:40:07 AM
BRIAN,

Quote
Please will someone say it.. WxLua was the correct scripting environment!

It's fantastic Brian and a good choice.  ;)


Just remember that there are a lot of folks that have no programing experience. So just take that into consideration
by asking what needs to be done so that Mach4 is functional for those folks.
Lua to me is something that occurs in Hawaii.  :D
Left my programming skills on the VAX mainframe  ::) a long time ago.......... hey, hey, you were just a concept at that time. ;D

- One could go to http://www.lua.org/manual/5.1/manual.html#5.5 for a manual and then find some Lua basic tutoring.
  For a non programmer it's more than disheartening.

- Maybe better than a manual would be examples of basic stuff  that folks can manipulate and learn from.
  Surely this will come about over time.
 
So keep the examples coming as they are appreciated guys and surely your talents will be called upon.

Want to go to the feast ...just studying how to get there, :)
RICH
 
Title: Re: Load GCode from fixed directory - for TP
Post by: BR549 on May 09, 2014, 03:46:40 PM
What I run into is Each programmer has a different style It seems to me that Brian Lua code and method are NOTHING like Les's (sheetcam) code and method.

IT would seem that METHOD is the key and you will not learn that from teh basic LUA manuals and examples.

The manual needs to written on the specifics of MAch4 NOT how to program a cool 3d game program. It NEEDS to explain what ALL those calls actually do.

Having a LIST means nothing without how they are used in "MAch4".  PURE Lua is not very easy as you have to do all the hard work when working with the GUI side. It seems the WX.Lua is much more freindly as it has all the COntrol features such as Textbox,etc where LUA does not you create the box from scratch, I THINK(;-)

(;-) TP