Hi All,
as I promised I thought I would start a new thread to show an idea that I have used on a few occasions to generate
Gcode files.
This thread started with:
https://www.machsupport.com/forum/index.php?topic=39284.0Where I wrote some code for OP to 'jewel' some material. Chad was interested in the idea of opening a file and putting
the Gcode in it rather than executing it immediately with successive mcCntlGcodeExecuteWait() API commands.
Here it is:
function m125()
local inst=mc.mcGetInstance()
-- create the wxFrame window
mainframe = wx.wxFrame( wx.NULL, -- no parent
wx.wxID_ANY, -- whatever for wxWindow ID
"DummyFrame", -- frame caption
wx.wxDefaultPosition, -- place the frame in default position
wx.wxDefaultSize, -- default frame size
wx.wxDEFAULT_FRAME_STYLE ) -- use default frame styles
-- create a panel in the frame
panel = wx.wxPanel(mainframe, wx.wxID_ANY)--We are not going to show it but we need to have this to use the File dialog
local file = wx.wxFileDialog(panel, "Select Data 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
path = file:GetPath()
fileHandle=io.open(path,"w+")
end
--
--
--
--
-- Jewel Data.....to be edited as required
--
local jewelWidth=50
local jewelLength=100
local toolDiameter=6
local nominalStepover=0.66
local plungeSpeed=300
local retractZ=2
local safeZ=20
local jewelDwellTime=500
--
-- End of data block
--
local startXpos
local startYpos
local jewelZheight
local stepoverX,numjewelX
local stepoverY,numjewelY
local i=0
local j=0
-- Save the current position as the start of the jeweling area....you have jogged to the start haven't you????
startXpos=mc.mcCntlGcodeInterpGetPos(inst,mc.X_AXIS)
startYpos=mc.mcCntlGcodeInterpGetPos(inst,mc.Y_AXIS)
jewelZheight=mc.mcCntlGcodeInterpGetPos(inst,mc.Z_AXIS)
-- Calculate the required step over to meet the nominal step over as closely as possible but be an integral
-- number of 'jewels'
-- Reduce jewelWidth in X and Y by the diameter of the tool
jewelWidth=jewelWidth-toolDiameter
jewelLength=jewelLength-toolDiameter
-- Calculate the exact number of 'jewels' required to match the nomininal Steppover
numjewelX=jewelWidth / (nominalStepover * toolDiameter)
numjewelY=jewelLength / (nominalStepover * toolDiameter)
-- Find the integer number of 'jewels'
numjewelX=math.modf(numjewelX)
numjewelY=math.modf(numjewelY)
-- Calculate the actual stepover to be used so that an integral number of 'jewels' are perfomed
stepoverX=jewelWidth / numjewelX
stepoverY=jewelLength / numjewelY
--
--
local retract="g0 z "..tostring(jewelZheight+retractZ)
local safeHeight="g0 z "..tostring(jewelZheight+safeZ)
--mc.mcCntlGcodeExecute(inst,retract..'\n'..'g1 f'..tostring(plungeSpeed)..'\n')
fileHandle:write(retract..'\n'..'g1 f '..tostring(plungeSpeed)..'\n')
for i=0,numjewelX,i+1 do
for j=0,numjewelY,j+1 do
jewelX=startXpos + (i * stepoverX)
jewelY=startYpos + (j * stepoverY)
--mc.mcCntlGcodeExecute(inst,'g0 x '..tostring(jewelX)..' y '.. tostring(jewelY)..'\n'..
-- 'g1 z '..tostring( jewelZheight)..'\n'..
-- 'g4 p'..tostring(jewelDwellTime)..'\n'..
-- retract..'\n')
fileHandle:write('g0 x '..tostring(jewelX)..' y '..tostring(jewelY)..'\n')
fileHandle:write('g1 z '..tostring(jewelZheight)..'\n')
fileHandle:write('g4 p '..tostring(jewelDwellTime)..'\n')
fileHandle:write(retract..'\n')
end
end
--mc.mcCntlGcodeExecuteWait(inst,safeHeight)
fileHandle:write(safeHeight..'\n')
fileHandle:flush()
fileHandle:close()
end
if (mc.mcInEditor()==1)then
m125()
end
Essentially all I have done is open a file dialogue so you can open a new file, or open an existing file with a normal Browse window
and then use exactly the same code that did the jeweling but replaced the mc.CntlGcodeExecuteWait() commands (I just
commented them out) with suitable file write commands.
Note that this code will run if you MDI <m125>.
The procedure would then be:
1) Jog to the location of the first (lower lefthand) 'jewel'
2) Lower the Z axis until the tool/brush makes contact with the material with sufficient force to effect the jewel
3) MDI <m125>
I have attached a coy of the file generated. Not very sophisticated....at best a poor mans Wizard.....and I am a poor man!
Craig