ToolpathSaver
This object is used to save toolpaths entirely from script. It gives access to the set of PostProcessors available to the program and holds a list of toolpaths to be saved.
IMPORTANT: It is the script writers responsibility to ensure that all the toolpaths added to the ToolpathSaver object are suitable for saving to one file using the selected post processor. The ToolpathSaver gives low level access to the toolpath output from the program and will write what ever toolpaths you specify to a single file irrespective of the tool geometry or the post processors support for tool changing. It is the responsibility of the script writer to ensure that a tool changing post is selected if multiple toolpaths using different tools are output. The :IsCompatible method of the Tool object can be used to check if tools used for different toolpaths are suitable for outputting to a single file if a tool changer is not available.
Example Code:
-- [[ ------------------------ DoAllToolpathsUseSameTool ----------------------------------- | | Check if all the toolpaths in the passed list use the same tool. If they do, we can | save all the toolpaths to the same file, regardless of whether the post supports | toolchanging. If the toolpaths use different tools and the post does not support tool | changing, the toolpaths will need to be saved individually | ]] function DoAllToolpathsUseSameTool(toolpath_ids, toolpath_manager) local tool = nil for i,toolpath_id in ipairs(toolpath_ids) do local pos = toolpath_manager:Find(toolpath_id) if pos == nil then MessageBox("Failed to find toolpath " i) return false end -- end if local toolpath = toolpath_manager:GetAt(pos) -- do we have an existing tool to check against if tool == nil then -- no this is first toolpath Note: save a copy of tool to check against tool = toolpath.Tool else -- check if this tool is compatible with previous tools if not tool:IsCompatibleTool(toolpath.Tool) then return false -- we have a mixture of tools end -- end if end -- end for end -- end for return true end -- end function -- [[ ------------------------ DoAllToolpathsUseSameTool ----------------------------------- |
Constructor
ToolpathSaver()
Create a new object which can be used to save toolpaths
Properties
.DefaultPost
Interaction: Read Only
Returns: (PostPInfo) the currently selected post processor within the program
.NumberOfToolpaths
Interaction: Read Only
Returns: (integer)the number of toolpaths currently held by this object ready for saving. Toolpaths are added to the object using the:AddToolpaths() method.
Methods
:GetNumPosts()
Returns: (number of post processers the program knows about. This is usually used to iterate through all the posts using:GetPostAtIndex
:AddToolpath(Toolpath toolpath)
Add the passed toolpath to the list of toolpaths to save managed by this object. Retunrs true if toolpath added to list ok. toolpath (Toolpath) toolpath to be saved
:ClearToolpathList()
Clear the list of toolpaths to save managed by this object.
:GetNumPosts()
Returns: (number of post processers the program knows about. This is usually used to iterate through all the posts using:GetPostAtIndex
:GetPostAtIndex(integer post_index)
Returns: (the post processor (PostPInfo) for the specified index. post_index (integer) index of post to return. The index go from 0 to num_posts negtive 1
:GetPostWithName(string post_name)
Returns: (the post processor (PostPInfo) with the specified name. This is the name displayed in the drop down list in the program. post_name (string)name of post to return.
:GetPostWithFilename(string post_file_name)
Returns: (the post processor (PostPInfo) with the specified file name. This is the name of the .pp file on disk without the path. post_file_name (string) filename of post to return.
.CreatePost(string post_file_path)
Create a new post processor from the given file. This is the full path to the .pp file.
Returns: a PostPInfo (or nil if something went wrong). post_file_path (string) path to the .pp file
:SaveToolpaths(PostPInfo postp, string filename, bool output_to_mc)
Save all the toolpaths which have been added with:AddToolpath using passed post processor to passed filename,
Returns: (bool) true if file saved OK, false if an error occurs. postp (PostPInfo) Post processor to use to save file filename (string) Full pathname to file to be saved. This MUST include the extension you want for the file as well. output_to_mc (bool) if true AND the post processor supports direct output to the machine the file will be sent to the machine after saving.
For Example
local toolpath_manager = ToolpathManager() if toolpath_manager.IsEmpty then MessageBox("There are no toolpaths to save") return false end local output_path = "c:\\temp\\test_toolpath_output.txt" -- get post processor to use for saving: local toolpath_saver = ToolpathSaver(); local post = toolpath_saver:GetPostWithName("Text Output Arcs (mm) (*.txt)") if post == nil then MessageBox("Failed to load Post Processor with name " post_name) Return false end -- save toolpath to file: local toolpath_names = "" -- we keep a list of toolpaths we save if selected_only then local toolpath = toolpath_manager:GetSelectedToolpath() if toolpath == nil then MessageBox("There is no currently selected toolpath") return false end -- if end toolpath_saver:AddToolpath(toolpath) toolpath_names = toolpath.Name "\n" else -- we are saving all toolpaths: local pos = toolpath_manager:GetHeadPosition() while pos ~= nil do local toolpath toolpath, pos = toolpath_manager:GetNext(pos) toolpath_saver:AddToolpath(toolpath) toolpath_names = toolpath_names toolpath.Name "\n" end -- while end end -- if end local success = toolpath_saver:SaveToolpaths(post, output_path, false) if not success then MessageBox("Failed to save toolpath(s)\n\n" toolpath_names "\nto file\n" output_path ) return false end -- if end MessageBox("Saved toolpath(s)\n\n" toolpath_names "\nto file\n" output_path "\nUsing post\n" post.Name)
References
Please Note: The base material for the contents found in this WiKi was sourced from Vectric Lua Interface for Gadgets, version 2.05, published September 12, 2018. by Vectric Ltd. Most current document from Vertric can be downloaded at Vertric Developer Information