Hello Guest it is November 20, 2019, 02:49:42 PM

Author Topic: Export tool table  (Read 3767 times)

0 Members and 1 Guest are viewing this topic.

Offline BR549

*
  •  6,916 6,916
    • View Profile
Export tool table
« 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
« Last Edit: May 15, 2014, 11:03:14 AM by BR549 »

Offline Bodini

*
  •  216 216
    • View Profile
Re: Export tool table
« Reply #1 on: May 15, 2014, 05:23:13 PM »
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

Code: [Select]

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
« Last Edit: May 15, 2014, 05:30:20 PM by Bodini »

Offline Bodini

*
  •  216 216
    • View Profile
Re: Export tool table
« Reply #2 on: May 15, 2014, 05:28:53 PM »
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).
Re: Export tool table
« Reply #3 on: May 15, 2014, 06:12:17 PM »
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
« Last Edit: May 15, 2014, 06:14:22 PM by Ya-Nvr-No »
Re: Export tool table
« Reply #4 on: May 15, 2014, 07:13:06 PM »
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 :)

Offline Bodini

*
  •  216 216
    • View Profile
Re: Export tool table
« Reply #5 on: May 15, 2014, 07:42:49 PM »
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
Re: Export tool table
« Reply #6 on: May 15, 2014, 07:54:52 PM »
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.

Offline smurph

*
  • *
  •  1,151 1,151
  • "That there... that's an RV."
    • View Profile
Re: Export tool table
« Reply #7 on: May 15, 2014, 08:14:25 PM »
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

Offline BR549

*
  •  6,916 6,916
    • View Profile
Re: Export tool table
« Reply #8 on: May 15, 2014, 08:48:16 PM »
WOW I thought one would open the tool table file parse the data and write to a text file.



(;-) TP

Offline BR549

*
  •  6,916 6,916
    • View Profile
Re: Export tool table
« Reply #9 on: May 15, 2014, 09:26:33 PM »
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
« Last Edit: May 15, 2014, 09:40:21 PM by BR549 »