Hello Guest it is March 29, 2024, 02:23:29 AM

Author Topic: mcCntrlGcodeExecuteWait fail  (Read 2798 times)

0 Members and 1 Guest are viewing this topic.

Re: mcCntrlGcodeExecuteWait fail
« Reply #10 on: April 23, 2018, 05:33:38 PM »
So I mentioned that I made a wizard to make G Code.  I redid the wizard to do this, so it made a panel with buttons.

How do I Get it to save the G Code into a file from a Macro?

Here is a seriously stripped down section of code from the Bolt Hole Wizard.  It is all I want to use for now... Just generating G Code from a button press.

function m501()
     --Populate variables.
     local x_center = 0
     local y_center = 0
     local Date = (os.date("%x  %X "))
    
--First Line of G Code.
     local gcode = string.format ("(Bolt Hole Wizard.) \n")
     gcode = gcode .. string.format ("(File created on ").. tostring(Date) .. (")\n")

--Safe Line.
     gcode = gcode .. ("G00 G90 G80 G40 G49 G54 \n")

--Go To Z Safe Height G53 Z0.
     gcode = gcode .. "G00 G53 Z0.00 \n"

--Set Spindle Direction.
     gcode = gcode .. "M3 \n"


--Set Coolant Type.
     gcode = gcode .. "M8 \n"

--G Code Comment
     gcode = gcode .. "(Begin Cycle.)\n"

--Go To Z Safe Height G53 Z0.
     gcode = gcode .. "G00 G53 Z0.00 \n"

--Last Lines of G Code  
       gcode = gcode .. "G80\nM05M09\nG00 G53 Y0.00\nM30\n"
-----------------------------------------------------------


     --local file = wx.wxFileDialog(panel, "Select Gcode File", "", "", "Text files (*.txt)|*.txt|Tap files (*.tap)|*.tap",
    --                        wx.wxFD_SAVE,wx.wxDefaultPosition,wx.wxDefaultSize, "File Dialog" );
         --if(file:ShowModal() == wx.wxID_OK)then
             local path = file:GetPath()
             --wx.wxMessageBox(tostring(path))
             io.output(io.open(path,"w"))
             io.write(gcode)
             io.close()
             mc.mcCntlLoadGcodeFile( 0, tostring(path))
         --end
     --SaveSettings()

mc.mc

end--m501()

if (mc.mcInEditor() == 1) then
   m501()
end
Chad Byrd

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: mcCntrlGcodeExecuteWait fail
« Reply #11 on: April 26, 2018, 11:03:57 PM »
Does this help?

Code: [Select]
--Button script
CreateNewFile()

function CreateNewFile()

local MyNum = wx.wxGetNumberFromUser("Select or enter a feed rate", "Feed Rate:", "Enter Feed Rate", 50, 1, 1500) --Default, min, max
local MyGcode = string.format("(File created using CreateNewFile function)\nF%0.4f", MyNum)
local MyFile = wx.wxGetCwd() .. "\\GcodeFiles\\MyFile.tap" --Define the file name and location
file = io.open(MyFile, "w+") --Open the file in update mode, all previous data is erased
--file = io.open(MyFile, "a+") --Append update mode, previous data is preserved, writing is only allowed at the end of file.
file:write (MyGcode) --Write the Gcode file
file:flush (MyFile) --Save written data
file:close (MyFile) --Close file

end
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: mcCntrlGcodeExecuteWait fail
« Reply #12 on: April 27, 2018, 08:13:23 AM »
Thanks Brett!
I got this to work!  Pretty cool stuff.   
Is there a way to make it open up the save dialog box?  I can't figure out where/how to make it do that.
Chad Byrd

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: mcCntrlGcodeExecuteWait fail
« Reply #13 on: May 15, 2018, 11:11:07 PM »
Saw this today, it should be pretty close I think.

local MyFile = wx.wxFileSelector("message", "C:\\Mach4Hobby\\GcodeFiles\\", "test.tap", ".tap", wx.wxFileSelectorDefaultWildcardStr, wx.wxFD_SAVE)

http://docs.wxwidgets.org/3.0.1/group__group__funcmacro__dialog.html
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!