Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: BR549 on May 15, 2014, 11:01:33 AM
-
HIYA Craig, see how popular you have become(;-)
Can you give a button code script example on HOW to export the tool table file out to a simple text file for printing in notepad. We could do that in Mach3 and it was a big help.
In the Mach3 version it ONLY exported tools that had values it did not create entries for empty tools
Thanks, (;-) TP
-
I had a spare 45 minutes to learn something Lua this afternoon so I gave it a shot. I know nothing of coding other than what I did in Mach 3 VB, so yes, I know this will be a juvenile effort. :D
It writes to a file called tool table.txt in the Mach 4 main folder.
Tested and works.
Regards,
Nick
file = io.open("tool table.txt","w") -- open a new current file
file:write(string.format("Tool# Length Length Wear Dia Dia Wear Description\n"))
inst = mc.mcGetInstance()
var1 = 7780 --start number
var2 = 10319 --end number
var3 = 10 --increment
local toolno = 1
for outer = var1, var2 ,var3 do
c1 = outer + 5 --length
c2 = outer + 6 --Length wear
c3 = outer + 8 --dia
c4 = outer + 9 --dia wear
w1 = mc.mcCntlGetPoundVar(inst, c1)
w2 = mc.mcCntlGetPoundVar(inst, c2)
w3 = mc.mcCntlGetPoundVar(inst, c3)
w4 = mc.mcCntlGetPoundVar(inst, c4)
desc= mc.mcToolGetDesc(inst, toolno)
ootput1 = string.format("Tool#%d %10.2f %10.2f %10.2f %10.2f %s\n",toolno,w1,w2,w3,w4,desc)
ootput2 = string.format("Tool#%d %9.2f %10.2f %10.2f %10.2f %s\n",toolno,w1,w2,w3,w4,desc)
ootput3 = string.format("Tool#%d %8.2f %10.2f %10.2f %10.2f %s\n",toolno,w1,w2,w3,w4,desc)
if w1 > 0 then
if toolno >= 100 then
file:write(ootput3)
elseif toolno >=10 then
file:write(ootput2)
else
file:write(ootput1)
end
end
var1 = var1+10
toolno = toolno + 1
end
file:close() -- close current file
-
I forgot to mention that it only uses the line that have a tool length. if it does not have a tool length then the line will not be printed, even if it does have other data. never used tool table myself so this was just a guess at a way to sort it out (see the "if w1 > 0 then" line).
-
Nick is the new expert on the block :)
Great job, and thanks
worked first time no problem at all, as advertised
Cut and paste to a button script
-
I had a spare 45 minutes to learn something Lua ..................
45 minutes huh, with no priors ? ? ? jeesh. What are you, a savant ? :)
Or a child prodigy ::), you did mention "juvenile". ;)
Sure hope you hang around, many of us will need you Nick. ;D
My next 45 minutes will be trying to understand it ... then I'll give up.
Did paste it in and it sure does work a treat.
Thanks for the post.
Russ :)
-
You're welcome Russ. It was a bit of fun. Don't get used to it though... the further into this Lua programming book I get, I more I just want to go push wood through the table saw and shut off the ol' brain. ;)
Really though, Lua is well documented, so if we can just get Mach 4 thoroughly documented... ;D ;D
ps- I meant to mention that in my code "ootput" is not a typo but rather a tribute to the Canadian we owe all our fun (or frustration) to, Art. I can make fun; I know a few Canadians (my wife, grandfather, etc.) ;D
-
Believe it or not, I got the oot part. As I was reading it, I could have sworn I could hear Mike Holmes narrating.
No kiddin', great tribute. Hope Art sees it.
-
The LUA stuff is dry reading isn't it?!?!?! I bought the books. I don't think I finished any of them. I instead search the internet for examples. I can stay awake that way...
Steve
-
WOW I thought one would open the tool table file parse the data and write to a text file.
(;-) TP
-
Looks Good, but just a note. The #var you used for the Diameter is actually a tool radius value so it needs to be Var X2 = diam.
Also a lttle BLURB to the staus line at the end of program would be nice to let you know it is done.
Thanks Bodini , (;-) TP
-
oK I added the date/time to the top of the report and reformated for IMP units AND added a blurb to the status bar to let you know it is finished AND sent it direct to notepad for viewing.
What I cannot figure out is HOW to Multiply the DIAM value *2. Nothing I have tried works.
(;-) TP
-
Followed corrections/suggestions by TP. Version 2. (or would that be 1.0.0.1 or something like that?) :D
--Version 2
file = io.open("tool table.txt","w") -- open a new current file
file:write("Mach 4 Tool table\n\n")
file:write(string.format("Tool# Length Length Wear Dia Dia Wear Description\n"))
inst = mc.mcGetInstance()
var1 = 7780 --start number
var2 = 10319 --end number
var3 = 10 --increment
local toolno = 1
for outer = var1, var2 ,var3 do
c1 = outer + 5 --length
c2 = outer + 6 --Length wear
c3 = outer + 8 --dia
c4 = outer + 9 --dia wear
w1 = mc.mcCntlGetPoundVar(inst, c1)
w2 = mc.mcCntlGetPoundVar(inst, c2)
w3 = (mc.mcCntlGetPoundVar(inst, c3)*2)
w4 = (mc.mcCntlGetPoundVar(inst, c4)*2)
desc= mc.mcToolGetDesc(inst, toolno)
ootput1 = string.format("Tool#%d %10.2f %10.2f %10.2f %10.2f %s\n",toolno,w1,w2,w3,w4,desc)
ootput2 = string.format("Tool#%d %9.2f %10.2f %10.2f %10.2f %s\n",toolno,w1,w2,w3,w4,desc)
ootput3 = string.format("Tool#%d %8.2f %10.2f %10.2f %10.2f %s\n",toolno,w1,w2,w3,w4,desc)
if w1 > 0 then
if toolno >= 100 then
file:write(ootput3)
elseif toolno >=10 then
file:write(ootput2)
else
file:write(ootput1)
end
end
var1 = var1+10
toolno = toolno + 1
end
file:write ("\n")
file:write(os.date("Created: %x %X"))
file:close() -- close current file
-
Oops, we crossed paths there. ha! look for vars w3 and w4.
-
I found my problem it was a FAT finger typing. I learned some LUA from SheetCam and Les has a different style for function names "File Name" in sheetcam is "fileName" where the second sylible starts with a CAP N.
Took me forever to get that in the brain NOW I have to figure out how to undo that habit.
I works great now. I also created a ToolTable export file to Import into SheetCam. Now to see IF I can do the reverse and IMPORT a Scam tool table into Mach4.
Thanks for the example, (;-) TP