Hello Guest it is March 28, 2024, 06:53:38 AM

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

0 Members and 1 Guest are viewing this topic.

Offline Jeff_Birt

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

Offline Jeff_Birt

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

Offline Jeff_Birt

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

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Load GCode from fixed directory - for TP
« Reply #5 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
Re: Load GCode from fixed directory - for TP
« Reply #6 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

Offline Jeff_Birt

*
  •  1,107 1,107
    • View Profile
    • Soigeneris
Re: Load GCode from fixed directory - for TP
« Reply #7 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
« Last Edit: May 07, 2014, 11:17:05 AM by Jeff_Birt »
Happy machining , Jeff Birt
 
Re: Load GCode from fixed directory - for TP
« Reply #8 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
Fixing problems one post at a time ;)

www.newfangledsolutions.com
www.machsupport.com

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Load GCode from fixed directory - for TP
« Reply #9 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