Hi all,
We have been trying to build our first gadget to help us create drilling only for cabinet fronts we receive from outside source
The gadget should import all DXF from a directory one by one. for each file it should move the vectors to a specific location, recalculate all toolpaths, save the nc file, delete all vectors and open a new dxf
at the moment we could not find how to delete all vectors before we import a new dxf, can you please help?
also I am sharing what we wrote so far a would love your comments and improvements
-- VECTRIC LUA SCRIPT
-- Function to display a message box
function MessageBox(title, message)
local mb = wx.wxMessageBox(message, title, wx.wxOK + wx.wxICON_INFORMATION)
end
-- Function to get the selected directory
function GetDirectory()
local openFileDialog = wx.wxDirDialog(nil, "Choose a directory", "", wx.wxDD_DEFAULT_STYLE + wx.wxDD_DIR_MUST_EXIST)
if openFileDialog:ShowModal() == wx.wxID_CANCEL then
return ""
end
return openFileDialog:GetPath()
end
-- Main function
function main()
-- Job Validation --
local job = VectricJob()
if not job.Exists then
DisplayMessageBox("Error: No job loaded")
return false ;
end
--selecting directory
local file_dialog = FileDialog()
file_dialog:FileOpen("","","")
local path = file_dialog.Directory
DisplayMessageBox(path)
--checking for valid directory
local directory = path
if directory == "" then
return
end
--going over selectet folder to map files
local fileList = ""
for file in io.popen("dir \""..directory.."\" /b"):lines() do
fileList = fileList..file
DisplayMessageBox(fileList)
local mr_file = path.. "\\"..fileList
DisplayMessageBox(mr_file)
job:ImportDxfDwg(mr_file)
--selecting vectors
local selection =job.Selection
-------- local selection_index = selection.count
DisplayMessageBox(tostring(selection.Count))
local vocter = Vector2D(50,50)
local trans = TranslationMatrix2D(vocter)
selection:Transform(trans)
local toolpath_mgr = ToolpathManager()
--checking selection on cad objects to retreive size data
local pos = selection:GetTailPosition()
local object
local uid_list = UUID_List()
object, pos = selection:GetPrev(pos)
local bb2d = Box2D(object:GetBoundingBox())
DisplayMessageBox(tostring(bb2d.XLength))
DisplayMessageBox(tostring(bb2d.YLength))
pos = selection:GetTailPosition()
--saving localy the x y values
for i = selection.Count,1,-1 do
object, pos = selection:GetPrev(pos)
uid_list:AddHead(object.RawId)
end
local x_value = tostring(bb2d.XLength)
local y_value = tostring(bb2d.YLength)
local name_is = x_value.. "X".. y_value
DisplayMessageBox(name_is)
toolpath_mgr:RecalculateAllToolpaths()
DisplayMessageBox(tostring(toolpath_mgr.Count))
--add the toolpath to saver
local pos_tool = toolpath_mgr:GetTailPosition()
local toolpath
local tps = ToolpathSaver()
for i=toolpath_mgr.Count,1,-1 do
toolpath, pos_tool = toolpath_mgr:GetNext(pos_tool)
--DO SOMETHING WITH TOOLPATH ....
tps:AddToolpath(toolpath)
end
--saving to nc
local post_pro = tps.DefaultPost
tps:SaveToolpaths(post_pro,directory.. name_is..".nc",false)
--------------------------------------------------------------
--------------------------------------------------------------
fileList = ""
--locating the dxf and saving
--sjob.Selection
-- DisplayMessageBox(tostring(job.Selection))
---clear the used vector
end
return true
end
-- function end
-- ===================================================]]
help with first time gadget
- jimandi5000
- Vectric Wizard
- Posts: 941
- Joined: Wed Mar 11, 2015 6:50 pm
- Model of CNC Machine: Home Made 60 x 120
- Location: North Houston Tx.
- Contact:
Re: help with first time gadget
Hi smithori,smithori wrote: ↑Thu May 25, 2023 5:24 amHi all,
We have been trying to build our first gadget to help us create drilling only for cabinet fronts we receive from outside source
The gadget should import all DXF from a directory one by one. for each file it should move the vectors to a specific location, recalculate all toolpaths, save the nc file, delete all vectors and open a new dxf
at the moment we could not find how to delete all vectors before we import a new dxf, can you please help?
also I am sharing what we wrote so far a would love your comments and improvements
-- VECTRIC LUA SCRIPT
-- Function to display a message box
function MessageBox(title, message)
local mb = wx.wxMessageBox(message, title, wx.wxOK + wx.wxICON_INFORMATION)
end
-- Function to get the selected directory
function GetDirectory()
local openFileDialog = wx.wxDirDialog(nil, "Choose a directory", "", wx.wxDD_DEFAULT_STYLE + wx.wxDD_DIR_MUST_EXIST)
if openFileDialog:ShowModal() == wx.wxID_CANCEL then
return ""
end
return openFileDialog:GetPath()
end
-- Main function
function main()
-- Job Validation --
local job = VectricJob()
if not job.Exists then
DisplayMessageBox("Error: No job loaded")
return false ;
end
--selecting directory
local file_dialog = FileDialog()
file_dialog:FileOpen("","","")
local path = file_dialog.Directory
DisplayMessageBox(path)
--checking for valid directory
local directory = path
if directory == "" then
return
end
--going over selectet folder to map files
local fileList = ""
for file in io.popen("dir \""..directory.."\" /b"):lines() do
fileList = fileList..file
DisplayMessageBox(fileList)
local mr_file = path.. "\\"..fileList
DisplayMessageBox(mr_file)
job:ImportDxfDwg(mr_file)
--selecting vectors
local selection =job.Selection
-------- local selection_index = selection.count
DisplayMessageBox(tostring(selection.Count))
local vocter = Vector2D(50,50)
local trans = TranslationMatrix2D(vocter)
selection:Transform(trans)
local toolpath_mgr = ToolpathManager()
--checking selection on cad objects to retreive size data
local pos = selection:GetTailPosition()
local object
local uid_list = UUID_List()
object, pos = selection:GetPrev(pos)
local bb2d = Box2D(object:GetBoundingBox())
DisplayMessageBox(tostring(bb2d.XLength))
DisplayMessageBox(tostring(bb2d.YLength))
pos = selection:GetTailPosition()
--saving localy the x y values
for i = selection.Count,1,-1 do
object, pos = selection:GetPrev(pos)
uid_list:AddHead(object.RawId)
end
local x_value = tostring(bb2d.XLength)
local y_value = tostring(bb2d.YLength)
local name_is = x_value.. "X".. y_value
DisplayMessageBox(name_is)
toolpath_mgr:RecalculateAllToolpaths()
DisplayMessageBox(tostring(toolpath_mgr.Count))
--add the toolpath to saver
local pos_tool = toolpath_mgr:GetTailPosition()
local toolpath
local tps = ToolpathSaver()
for i=toolpath_mgr.Count,1,-1 do
toolpath, pos_tool = toolpath_mgr:GetNext(pos_tool)
--DO SOMETHING WITH TOOLPATH ....
tps:AddToolpath(toolpath)
end
--saving to nc
local post_pro = tps.DefaultPost
tps:SaveToolpaths(post_pro,directory.. name_is..".nc",false)
--------------------------------------------------------------
--------------------------------------------------------------
fileList = ""
--locating the dxf and saving
--sjob.Selection
-- DisplayMessageBox(tostring(job.Selection))
---clear the used vector
end
return true
end
-- function end
-- ===================================================]]
Good to hear you are trying your hand at writing your own Gadget. I am sure you can do it and if you need help send me a PM.
I do not think you can Delete Vectors with a gadget.
JimAndi
Thanks,
Jim
Jim
- adze_cnc
- Vectric Wizard
- Posts: 3624
- Joined: Sat Jul 27, 2013 10:08 pm
- Model of CNC Machine: AXYZ 4008
- Location: Vancouver, BC, Canada
Re: help with first time gadget
You might want to enclose code posted here using the code tags (the icon with the </> on it). Quote this message to see what you'd need to type.
Code: Select all
-- sample code
local a = 1
print(a)
- adze_cnc
- Vectric Wizard
- Posts: 3624
- Joined: Sat Jul 27, 2013 10:08 pm
- Model of CNC Machine: AXYZ 4008
- Location: Vancouver, BC, Canada
Re: help with first time gadget
As well, have you looked at the built-in "DXF Batch Processor" gadget? To locate it from VCarve / Aspire's File menu do:
Re: help with first time gadget
Thanks! Will use it next timeadze_cnc wrote: ↑Thu May 25, 2023 9:09 amYou might want to enclose code posted here using the code tags (the icon with the </> on it). Quote this message to see what you'd need to type.
Code: Select all
-- sample code local a = 1 print(a)
Do you know anything on how to delete vectors from a gadget? There must be a way
Re: help with first time gadget
For each vector that you want to remove, you need to get a CadLayer object that contains it and then use RemoveObject or RemoveAt method:smithori wrote: ↑Sun May 28, 2023 6:14 amThanks! Will use it next timeadze_cnc wrote: ↑Thu May 25, 2023 9:09 amYou might want to enclose code posted here using the code tags (the icon with the </> on it). Quote this message to see what you'd need to type.
Code: Select all
-- sample code local a = 1 print(a)
Do you know anything on how to delete vectors from a gadget? There must be a way
Code: Select all
local object = layer:GetAt(pos)
layer:RemoveObject(object)
-- or
layer:RemoveAt(pos)
Greg K