I was wrestling with a problem that needed a function to act upon a tool but it was becoming unwieldy passing tool instances to and from that function. I was needing temporary instances with their own names and things were getting out of hand.
I realised (had an epiphany?) that you can extend the Vectric gadget API's objects by adding your own methods [those ":" commands. e.g. the existing Tool:ConvertRateUnitsTo(new_rate_code) ].
For example the API has a Tool() object that has various constructors and methods. The following adds a simple ":ShowToolRPM" method. To test it yourself copy the code. Load or create a new job. Select Edit > Paste:
Code: Select all
-- VECTRIC LUA SCRIPT
function Tool:ShowToolRPM()
DisplayMessageBox("You spin me right round at " .. self.SpindleSpeed .. " rpm")
end
function main(script_path)
local endMill = Tool("Lua End Mill", Tool.END_MILL)
endMill.SpindleSpeed = 10000
endMill:ShowToolRPM()
local vbit = Tool("Lua VBit Mill", Tool.VBIT)
vbit.SpindleSpeed = 17500
vbit:ShowToolRPM()
return true
end
Code: Select all
RegValue = RegistryWriter:SetDouble("MillTool1.FeedRate" , MillTool1.FeedRate)
RegValue = RegistryWriter:SetBool("MillTool1.InMM", MillTool1.InMM)
...
RegValue = RegistryWriter:SetDouble("MillTool8.ClearStepover", MillTool8.ClearStepover)
RegValue = RegistryWriter:SetInt("MillTool8.ToolNumber", MillTool8.ToolNumber)
Code: Select all
function Tool:RegWrite(registryrWriter, keyPrefix)
local k = keyPrefix
local w = registryWriter
w:SetDouble(k .. "FeedRate", self.FeedRate)
w:SetBool(k .. "InMM", self.InMM)
w:SetString(k .. "Name", self.Name)
w:SetDouble(k .. "PlungeRate", self.PlungeRate)
w:SetInt(k .. "RateUnits", self.RateUnits)
w:SetInt(k .. "SpindleSpeed", self.SpindleSpeed)
w:SetDouble(k .. "Stepdown", self.Stepdown)
w:SetDouble(k .. "Stepover" , self.Stepover)
w:SetDouble(k .. "ToolDia" , self.ToolDia)
w:SetDouble(k .. "VBit_Angle", self.VBit_Angle)
w:SetDouble(k .. "ClearStepover", self.ClearStepover)
w:SetInt(k .. "ToolNumber", self.ToolNumber)
end
function RegistryWrite()
local RegistryWriter = Registry(RegName)
-- ...
local key = "MillTool"
MillTool1:RegWrite(RegWriter, key.."1.")
MillTool2:RegWrite(RegWriter, key.."2.")
MillTool3:RegWrite(RegWriter, key.."3.")
MillTool4:RegWrite(RegWriter, key.."4.")
MillTool5:RegWrite(RegWriter, key.."5.")
MillTool6:RegWrite(RegWriter, key.."6.")
MillTool7:RegWrite(RegWriter, key.."7.")
MillTool8:RegWrite(RegWriter, key.."8.")
-- ...
end