Hello Guest it is March 29, 2024, 01:50:03 AM

Author Topic: Load GCode from fixed directory - for TP  (Read 13605 times)

0 Members and 1 Guest are viewing this topic.

Re: Load GCode from fixed directory - for TP
« Reply #10 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.

Offline Jeff_Birt

*
  •  1,107 1,107
    • View Profile
    • Soigeneris
Re: Load GCode from fixed directory - for TP
« Reply #11 on: May 07, 2014, 11:42:28 AM »
What do you mean, "does not like this"?

Jeff
Happy machining , Jeff Birt
 
Re: Load GCode from fixed directory - for TP
« Reply #12 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!
Fixing problems one post at a time ;)

www.newfangledsolutions.com
www.machsupport.com

Offline Jeff_Birt

*
  •  1,107 1,107
    • View Profile
    • Soigeneris
Re: Load GCode from fixed directory - for TP
« Reply #13 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.
Happy machining , Jeff Birt
 

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Load GCode from fixed directory - for TP
« Reply #14 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
« Last Edit: May 07, 2014, 12:01:06 PM by BR549 »
Re: Load GCode from fixed directory - for TP
« Reply #15 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

Offline Jeff_Birt

*
  •  1,107 1,107
    • View Profile
    • Soigeneris
Re: Load GCode from fixed directory - for TP
« Reply #16 on: May 07, 2014, 12:25:58 PM »
Look in the lower right corner of the dialog....

Happy machining , Jeff Birt
 
Re: Load GCode from fixed directory - for TP
« Reply #17 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);

Offline Jeff_Birt

*
  •  1,107 1,107
    • View Profile
    • Soigeneris
Re: Load GCode from fixed directory - for TP
« Reply #18 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);
Happy machining , Jeff Birt
 
Re: Load GCode from fixed directory - for TP
« Reply #19 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
« Last Edit: May 07, 2014, 06:40:33 PM by Ya-Nvr-No »