ToolpathManager: Difference between revisions

From SDK
Jump to navigation Jump to search
No edit summary
 
(One intermediate revision by the same user not shown)
Line 132: Line 132:
   tool.Stepdown = tool_stepdown
   tool.Stepdown = tool_stepdown
   tool.Stepover = tool_dia * 0.25
   tool.Stepover = tool_dia * 0.25
   tool.RateUnits = Tool.MM_SEC  -- MM_SEC, MM_MIN, METRES_MIN, INCHES_SEC, INCHES_MIN, FEET_MIN
   tool.Rate_Units = Tool.MM_SEC  -- MM_SEC, MM_MIN, METRES_MIN, INCHES_SEC, INCHES_MIN, FEET_MIN
   tool.FeedRate = 30
   tool.Feed_Rate = 30
   tool.PlungeRate = 10
   tool.Plunge_Rate = 10
   tool.SpindleSpeed = 20000
   tool.Spindle_Speed = 20000
   tool.ToolNumber = 1
   tool.Tool_Number = 1
   tool.VBitAngle = 90.0                -- used for vbit only
   tool.VBit_Angle = 90.0                -- used for vbit only
   tool.ClearStepover = tool_dia * 0.5  -- used for vbit only
   tool.ClearStepover = tool_dia * 0.5  -- used for vbit only
    
    
Line 403: Line 403:
                                               pocket_data,
                                               pocket_data,
                                               pos_data,
                                               pos_data,
      geometry_selector,
                                              geometry_selector,
                                               create_2d_previews,
                                               create_2d_previews,
                                               display_warnings
                                               display_warnings

Latest revision as of 10:24, 16 November 2024

Back.jpg

The ToolpathManager object is used to handle all the toolpaths within the program. Like the MaterialBlock object there is one instance within the program which is accessed by any ToolpathManager object. For the initial release, the ToolpathManager is only used to create new toolpaths, load templates and recalculate all toolpaths, for future releases Vectric may offer more access to existing toolpaths depending on demand.


Constructor

ToolpathManager

Returns: a new object which refers to the single toolpath manager within the program.

For Example:

local toolpath_mgr = ToolpathManager() 


Properties

.Count

Interaction: Read Only

Returns: (integer) the number of toolpaths



.IsEmpty

Interaction: Read Only

Returns: (bool) true if there are no toolpaths



.NumVisibleToolpaths

Interaction: Read Only

Returns: (integer) the number of visible toolpaths


Methods

:AddExternalToolpath( ExternalToolpath toolpath)

Top.jpg

Adds the passed toolpath to the list of toolpaths in the job.

Returns: (bool) true if the toolpath was added OK, else false. See the documentation for ExternalToolpath for information on how to create the actual toolpath itself.
toolpath (ExternalToolpath) toolpath created in a lua script which is added to job






===:CreateProfilingToolpath(String name,Tool tool,ProfileParameterData profile_data,RampingData ramping_data,LeadInOutData lead_data,ToolpathPosData pos_data,GeometrySelector geometry_selector,bool create_2d_preview,bool interactive) Creates a profiling toolpath for the currently selected vectors.

Returns: the UUID for the toolpath created.
name(string) Name for the toolpath to be created
tool (Tool) Tool to use for the toolpath
profile_data (ProfileParameterData) Settings for profiling depth, inside or outside etc
ramping_data (RampingData) Settings for ramping lead_data (LeadInOutData) Settings for lead in or out pos_data (ToolpathPosData) Settings for home position, safe z etc
geometry_selector (GeometrySelector) Can be used to automatically select vectors on layers etc
create_2d_preview(bool) If true create preview vectors in 2d view interactive(bool) If true display warnings etc to user

Example Code: CreateLayerProfileToolpath

from Profile_Vectors_On_Layer.lua
--[[  ---------------- CreateLayerProfileToolpath ----------------  
|
|   Create an outside Profile toolpath within the program for vectors on the passed layer
|  Parameters:
|     job               -- Job we are working with
|     layer_name        -- Name of layer we will profile vectors for
|     name              -- Name for toolpath
|     start_depth       -- Start depth for toolpath below surface of material
|     cut_depth         -- cut depth for profile toolpath
|     tool_dia          -- diameter of end mill to use
|     tool_stepdown     -- stepdown for tool
|     tool_in_mm        -- true if tool size and stepdown are in mm
|
|  Return Values:
|     true if toolpath created OK else false
|
]]

function CreateLayerProfileToolpath( job, layer_name, name , start_depth, cut_depth, tool_dia, tool_stepdown, tool_in_mm)


   -- clear current selection
   local selection = job.Selection
   selection:Clear()
   
   -- get layer
   local layer = job.LayerManager:FindLayerWithName(layer_name)
   
   if layer == nil then
      DisplayMessageBox("No layer found with name = " .. "\"" ..  layer_name .. "\"")
      return false
   end

   
   -- select all closed vectors on the layer
   if not SelectVectorsOnLayer(layer, selection, true, false, true) then
      DisplayMessageBox("No closed vectors found on layer " .. "\"" .. layer_name .. "\"")
      return false
   end
   
   -- Create tool we will use to machine vectors
   local tool = Tool(
                    "Lua End Mill", 
                    Tool.END_MILL       -- BALL_NOSE, END_MILL, VBIT
                    )
                     
   tool.InMM = tool_in_mm
   tool.ToolDia = tool_dia
   tool.Stepdown = tool_stepdown
   tool.Stepover = tool_dia * 0.25
   tool.Rate_Units = Tool.MM_SEC  -- MM_SEC, MM_MIN, METRES_MIN, INCHES_SEC, INCHES_MIN, FEET_MIN
   tool.Feed_Rate = 30
   tool.Plunge_Rate = 10
   tool.Spindle_Speed = 20000
   tool.Tool_Number = 1
   tool.VBit_Angle = 90.0                -- used for vbit only
   tool.ClearStepover = tool_dia * 0.5  -- used for vbit only
  

   -- we will set home position and safe z relative to material block size  
   local mtl_block = MaterialBlock()  
   local mtl_box = mtl_block.MaterialBox
   local mtl_box_blc = mtl_box.BLC
  
   -- Create object used to set home position and safez gap above material surface
   local pos_data = ToolpathPosData()
   pos_data:SetHomePosition(mtl_box_blc.x, mtl_box_blc.y, mtl_box.TRC.z + (mtl_block.Thickness * 0.2) )
   pos_data.SafeZGap = mtl_block.Thickness * 0.1
  
  
   -- Create  object used to pass profile options
   local profile_data = ProfileParameterData()
      -- start depth for toolpath
      profile_data.StartDepth = start_depth
      
      -- cut depth for toolpath this is depth below start depth
      profile_data.CutDepth = cut_depth
      
      -- direction of cut - ProfileParameterData.CLIMB_DIRECTION or ProfileParameterData.CONVENTIONAL_DIRECTION
      profile_data.CutDirection = ProfileParameterData.CLIMB_DIRECTION
      
      -- side we machine on - ProfileParameterData.PROFILE_OUTSIDE,  ProfileParameterData.PROFILE_INSIDE or ProfileParameterData.PROFILE_ON
      profile_data.ProfileSide = ProfileParameterData.PROFILE_OUTSIDE
      
      -- Allowance to leave on when machining
      profile_data.Allowance = 0.0
   
      -- true to preserve start point positions, false to reorder start points to minimise toolpath length   
      profile_data.KeepStartPoints = false
      
      -- true if want to create 'square' external corners on toolpath
      profile_data.CreateSquareCorners = false
      
      -- true to perform corner sharpening on internal corners (only with v-bits)
      profile_data.CornerSharpen = false
      
      -- true to use tabs (position of tabs must already have been defined on vectors)
      profile_data.UseTabs = false
      -- length for tabs if being used
      profile_data.TabLength = 5.0
      -- Thickness for tabs if being used
      profile_data.TabThickness = 1.0
      -- if true then create 3d tabs else 2d tabs
      profile_data.Use3dTabs  = true
      
      -- if true in Aspire, project toolpath onto composite model
      profile_data.ProjectToolpath = false
      
   -- Create object used to control ramping
   local ramping_data = RampingData()
      -- if true we do ramping into toolpath
      ramping_data.DoRamping = false
      -- type of ramping to perform RampingData.RAMP_LINEAR , RampingData.RAMP_ZIG_ZAG or RampingData.RAMP_SPIRAL
      ramping_data.RampType = RampingData.RAMP_ZIG_ZAG
      -- how ramp is contrained - either by angle or distance RampingData.CONSTRAIN_DISTANCE or RampingData.CONSTRAIN_ANGLE
      ramping_data.RampConstraint = RampingData.CONSTRAIN_ANGLE
      -- if we are constraining ramp by distance, distance to ramp over
      ramping_data.RampDistance = 100.0
      -- if we are contraining ramp by angle , angle to ramp in at (in degrees)
      ramping_data.RampAngle = 25.0
      -- if we are contraining ramp by angle, max distance to travel before 'zig zaging' if zig zaging
      ramping_data.RampMaxAngleDist = 15
      -- if true we restrict our ramping to lead in section of toolpath
      ramping_data.RampOnLeadIn = false
      
   
   -- Create object used to control lead in/out
   local lead_in_out_data = LeadInOutData()
      -- if true we create lead ins on profiles (not for profile on) 
      lead_in_out_data.DoLeadIn = false
      -- if true we create lead outs on profiles (not for profile on) 
      lead_in_out_data.DoLeadOut = false
      -- type of leads to create LeadInOutData.LINEAR_LEAD or LeadInOutData.CIRCULAR_LEAD
      lead_in_out_data.LeadType = LeadInOutData.CIRCULAR_LEAD
      -- length of lead to create
      lead_in_out_data.LeadLength = 10.0
      -- Angle for linear leads
      lead_in_out_data.LinearLeadAngle = 45
      -- Radius for circular arc leads
      lead_in_out_data.CirularLeadRadius = 5.0
      -- distance to 'overcut' (travel past start point) when profiling
      lead_in_out_data.OvercutDistance = 0.0

   -- Create object which can used to automatically select geometry on layers etc
   local geometry_selector = GeometrySelector() 
   
   -- if this is true we create 2d toolpaths previews in 2d view, if false we dont
   local create_2d_previews = true
   
   -- if this is true we will display errors and warning to the user
   local display_warnings = true
   
   -- Create our toolpath

   local toolpath_manager = ToolpathManager()
 
   local toolpath_id = toolpath_manager:CreateProfilingToolpath(
                                              name,
                                              tool,
                                              profile_data,
                                              ramping_data,
                                              lead_in_out_data,
                                              pos_data,
											  geometry_selector,
                                              create_2d_previews,
                                              display_warnings
                                              )
   
   if toolpath_id  == nil  then
      DisplayMessageBox("Error creating toolpath")
      return false
   end                                                    

   return true  

end 

CreatePocketingToolpath()

Top.jpg

Usage: CreatePocketingToolpath(

String name,
Tool tool,
Tool area_clear_tool,
PocketParameterData pocket_data,
ToolpathPosData pos_data,
GeometrySelector geometry_selector,
bool create_2d_preview,
bool interactive
)

Creates a pocketing toolpath for the currently selected vectors. Return the UUID for the toolpath created.

name(string) Name for the toolpath to be created
tool (Tool) Tool to use for the toolpath. Note: must not be nil
area_clear_tool (Tool) Optional tool for area clearance can be nil
pocket_data (PocketParameterData) Setting for pocketing depth, style etc
pos_data(ToolpathPosData) Settings for home position, safe z etc
geometry_selector (GeometrySelector) Can be used to automatically select vectors on layers etc
create_2d_preview(bool) If true create preview vectors in 2d view
interactive(bool) If true display warnings etc to user


Example Code: CreatePocketingToolpath

from Create_Pocketing_Toolpath.lua
 -- VECTRIC LUA SCRIPT
 require "strict"
 --[[  -------------- CreatePocketingToolpath --------------------------------------------------  
|
|   Create a Pocketing toolpath within the program for the currently selected vectors
|  Parameters:
|     name,                 -- Name for toolpath
|     start_depth           -- Start depth for toolpath below surface of material
|     cut_depth             -- cut depth for pocket toolpath
|     tool_dia              -- diameter of end mill to use
|     tool_stepdown         -- stepdown for tool
|     tool_stepover_percent -- percentage stepover for tool
|     tool_in_mm            -- true if tool size and stepdown are in mm
|
|  Return Values:
|     true if toolpath created OK else false
|
]]

function CreatePocketingToolpath( name , start_depth, cut_depth, tool_dia, tool_stepdown, tool_stepover_percent, tool_in_mm)

   -- Create tool we will use to machine vectors
   local tool = Tool(
                    "Lua End Mill", 
                    Tool.END_MILL       -- BALL_NOSE, END_MILL, VBIT
                    )
                     
   tool.InMM = tool_in_mm
   tool.ToolDia = tool_dia
   tool.Stepdown = tool_stepdown
   tool.Stepover = tool_dia * (tool_stepover_percent / 100)
   tool.RateUnits = Tool.MM_SEC  -- MM_SEC, MM_MIN, METRES_MIN, INCHES_SEC, INCHES_MIN, FEET_MIN
   tool.FeedRate = 30
   tool.PlungeRate = 10
   tool.SpindleSpeed = 20000
   tool.ToolNumber = 1
   tool.VBitAngle = 90.0                -- used for vbit only
   tool.ClearStepover = tool_dia * (tool_stepover_percent / 100)  -- used for vbit only
  
   -- we will set home position and safe z relative to material block size  
   local mtl_block = MaterialBlock()  
   local mtl_box = mtl_block.MaterialBox
   local mtl_box_blc = mtl_box.BLC
  
   -- Create object used to set home position and safez gap above material surface
   local pos_data = ToolpathPosData()
   pos_data:SetHomePosition(mtl_box_blc.x, mtl_box_blc.y, mtl_box.TRC.z + (mtl_block.Thickness * 0.2) )
   pos_data.SafeZGap = mtl_block.Thickness * 0.1
  
   -- Create  object used to pass pocketing options
   local pocket_data = PocketParameterData()
      -- start depth for toolpath
      pocket_data.StartDepth = start_depth
      
      -- cut depth for toolpath this is depth below start depth
      pocket_data.CutDepth = cut_depth
      
      -- direction of cut for offet clearance - ProfileParameterData.CLIMB_DIRECTION or ProfileParameterData.CONVENTIONAL_DIRECTION - NOTE: enum from ProfileParameterData
      pocket_data.CutDirection = ProfileParameterData.CLIMB_DIRECTION
      
      -- Allowance to leave on when machining
      pocket_data.Allowance = 0.0
      
      -- if true use raster clearance strategy , else use offset area clearance
      pocket_data.DoRasterClearance = true
      -- angle for raster if using raster clearance
      pocket_data.RasterAngle = 0
      -- type of profile pass to perform  PocketParameterData.PROFILE_NONE , PocketParameterData.PROFILE_FIRST orPocketParameterData.PROFILE_LAST
      pocket_data.ProfilePassType = PocketParameterData.PROFILE_LAST
      
      -- if true we ramp into pockets (always zig-zag)
      pocket_data.DoRamping = false
      --  if ramping, distance to ramp over
      pocket_data.RampDistance = 10.0
      
      -- if true in Aspire, project toolpath onto composite model
      pocket_data.ProjectToolpath = false

   -- Create object which can used to automatically select geometry on layers etc
  local geometry_selector = GeometrySelector() 
        
   -- if this is true we create 2d toolpaths previews in 2d view, if false we dont
   local create_2d_previews = true
   
   -- if this is true we will display errors and warning to the user
   local display_warnings = true
   
   -- if we are doing two tool pocketing define tool to use for area clearance
   local area_clear_tool = nil
   
   -- we just create a tool twice as large for testing here
   area_clear_tool = Tool(
                          "Lua Clearance End Mill", 
                          Tool.END_MILL       -- BALL_NOSE, END_MILL, VBIT
                          )
                     
   area_clear_tool.InMM = tool_in_mm
   area_clear_tool.ToolDia = tool_dia * 2
   area_clear_tool.Stepdown = tool_stepdown * 2
   area_clear_tool.Stepover = tool_dia * 2 *(tool_stepover_percent / 100)
   area_clear_tool.RateUnits = Tool.MM_SEC  -- MM_SEC, MM_MIN, METRES_MIN, INCHES_SEC, INCHES_MIN, FEET_MIN
   area_clear_tool.FeedRate = 30
   area_clear_tool.PlungeRate = 10
   area_clear_tool.SpindleSpeed = 20000
   area_clear_tool.ToolNumber = 1
   area_clear_tool.VBitAngle = 90.0                -- used for vbit only
   area_clear_tool.ClearStepover = tool_dia * 2 * (tool_stepover_percent / 100)  -- used for vbit only
   
   -- Create our toolpath

   local toolpath_manager = ToolpathManager()
 
   local toolpath_id = toolpath_manager:CreatePocketingToolpath(
                                              name,
                                              tool,
                                              area_clear_tool,
                                              pocket_data,
                                              pos_data,
                                              geometry_selector,
                                              create_2d_previews,
                                              display_warnings
                                              )
   
   if toolpath_id  == nil  then
      DisplayMessageBox("Error creating toolpath")
      return false
   end                                                    

   return true  

end


--[[  ----------- main --------------------------------------------------  
|
|  Entry point for script
|
]]

function main()

    -- Check we have a job loaded
    local job = VectricJob()
 
    if not job.Exists then
       DisplayMessageBox("No job loaded")
       return false;  
    end
 
   local selection = job.Selection
   if selection.IsEmpty  then
       MessageBox("Please select one or more closed vectors to pocket")
       return false  
    end
    
	local mtl_block = MaterialBlock()
	
    local start_depth = 0.0
    local cut_depth = mtl_block.Thickness * 0.25
    local tool_dia = 12.0
    local tool_stepdown = 2.5
    local tool_stepover_percent = 50.0
    local tool_in_mm = true
    
    local success = CreatePocketingToolpath( 
                                           "Lua Pocketing Toolpath", 
                                           start_depth, 
                                           cut_depth, 
                                           tool_dia, 
                                           tool_stepdown, 
                                           tool_stepover_percent,
                                           tool_in_mm 
                                           )
    
    
    return success;
end     

:CreateDrillingToolpath

Top.jpg

Usage: :CreateDrillingToolpath(

String name,
Tool tool,
DrillParameterData drilling_data,
ToolpathPosData pos_data,
GeometrySelectorgeometry_selector,
bool create_2d_preview,
bool interactive)

Creates a drilling toolpath for the currently selected vectors.

Returns: the UUID for the toolpath created.

name(string) Name for the toolpath to be created
tool(Tool) Tool to use for the toolpath
drill_data DrillParameterData Setting for drilling depth, peck etc
pos_data(ToolpathPosData) Settings for home position, safe z etc
geometry_selector(GeometrySelector) Can be used to automatically select vectors on layers etc
create_2d_preview(bool) If true create preview vectors in 2d view
interactive(bool) If true display warnings etc to user

Example Code: CreateDrillingToolpath

from Create_Drilling_Toolpath.lua

 -- VECTRIC LUA SCRIPT 
 require "strict"
function CreateDrillingToolpath( name , start_depth, cut_depth, retract_gap, tool_dia, tool_stepdown, tool_in_mm)

   -- Create tool we will use to machine vectors
   local tool = Tool(
                    "Lua Drill", 
                    Tool.THROUGH_DRILL       -- BALL_NOSE, END_MILL, VBIT, THROUGH_DRILL
                    )
                     
   tool.InMM = tool_in_mm
   tool.ToolDia = tool_dia
   tool.Stepdown = tool_stepdown
   tool.Stepover = tool_dia * 0.25
   tool.RateUnits = Tool.MM_SEC  -- MM_SEC, MM_MIN, METRES_MIN, INCHES_SEC, INCHES_MIN, FEET_MIN
   tool.FeedRate = 30
   tool.PlungeRate = 10
   tool.SpindleSpeed = 20000
   tool.ToolNumber = 1
   tool.VBitAngle = 90.0                -- used for vbit only
   tool.ClearStepover = tool_dia * 0.5  -- used for vbit only
  

  -- we will set home position and safe z relative to material block size  
   local mtl_block = MaterialBlock()  
   local mtl_box = mtl_block.MaterialBox
   local mtl_box_blc = mtl_box.BLC
  
   -- Create object used to set home position and safez gap above material surface
   local pos_data = ToolpathPosData()
   pos_data:SetHomePosition(mtl_box_blc.x, mtl_box_blc.y, mtl_box.TRC.z + (mtl_block.Thickness * 0.2) )
   pos_data.SafeZGap = mtl_block.Thickness * 0.1
  
   -- Create  object used to pass drilling options
   local drill_data = DrillParameterData()
      -- start depth for toolpath
      drill_data.StartDepth = start_depth
      
      -- cut depth for toolpath this is depth below start depth
      drill_data.CutDepth = cut_depth
      
      -- if true perform peck drilling
      drill_data.DoPeckDrill = retract_gap > 0.0
      
      -- distance to retract above surface when peck drilling
      drill_data.PeckRetractGap = retract_gap
      
      -- if true in Aspire, project toolpath onto composite model
      drill_data.ProjectToolpath = false
      
   -- Create object which can used to automatically select geometry on layers etc
   local geometry_selector = GeometrySelector() 
   
   -- if this is true we create 2d toolpaths previews in 2d view, if false we dont
   local create_2d_previews = true
   
   -- if this is true we will display errors and warning to the user
   local display_warnings = true
   
   -- Create our toolpath

   local toolpath_manager = ToolpathManager()
 
   local toolpath_id = toolpath_manager:CreateDrillingToolpath(
                                              name,
                                              tool,
                                              drill_data,
                                              pos_data,
											  geometry_selector,
                                              create_2d_previews,
                                              display_warnings
                                              )
   
   if toolpath_id  == nil  then
      DisplayMessageBox("Error creating toolpath")
      return false
   end                                                    

   return true  

end


--[[  ----------------- main ----------------- 
|
|  Entry point for script
|
]]

function main()

    -- Check we have a job loaded
    local job = VectricJob()
 
    if not job.Exists then
       DisplayMessageBox("No job loaded")
       return false;  
    end
 
   local selection = job.Selection
   if selection.IsEmpty  then
       MessageBox("Please select one or more vectors to drill")
       return false  
    end
    
	local mtl_block = MaterialBlock()
	
    local start_depth = 0.0
    local cut_depth = mtl_block.Thickness
    local tool_dia = 3.0
    local retract_gap = 1.0
    local tool_stepdown = 1.0
    local tool_in_mm = true
    
    local success = CreateDrillingToolpath( 
                                          "Lua Drilling Toolpath", 
                                          start_depth, 
                                          cut_depth, 
                                          retract_gap,
                                          tool_dia, 
                                          tool_stepdown, 
                                          tool_in_mm 
                                          )
    
    
    return success;
end    


:CreateVCarvingToolpath()

Top.jpg

Usage: :CreateVCarvingToolpath(

String name,
Tool tool,
Tool area_clear_tool,
VCarveParameterData vcarve_data,
PocketParameterData pocket_data,
ToolpathPosData pos_data,
GeometrySelector geometry_selector,
bool create_2d_preview,
bool interactive)

Creates a vcarving toolpath for the currently selected vectors.

Returns: the UUID for the toolpath created.

name(string) Name for the toolpath to be created
tool (Tool) Tool to use for the toolpath Note: must not be nil
area_clear_tool(Tool) Optional tool for area clearance can be nil
vcarve_data(VCarveParameterData) Settings for vcarving
pocket_data(PocketParameterData) Setting for pocketing depth, style etc
pos_data(ToolpathPosData) Settings for home position, safe z etc
geometry_selector(GeometrySelector) Can be used to automatically select vectors on layers etc
create_2d_preview(bool) If true create preview vectors in 2d view
interactive(bool) If true display warnings etc to user

Example Code: CreateVCarvingToolpath

 from Create_VCarving_Toolpath.lua
 -- VECTRIC LUA SCRIPT
 require "strict"
--[[  ------------- CreateVCarvingToolpath --------------------------------------------------  
|
|   Create a VCarving toolpath within the program for the currently selected vectors
|  Parameters:
|    name,                 -- name for toolpath
|    start_depth           -- start depth for toolpath below surface of material
|    flat_depth            -- flat depth - if 0.0 assume not doing flat bottom
|    vbit_angle            -- angle of vbit to use
|    vbit_dia              -- diameter of VBit  to use
|    vbit_stepdown         -- stepdown for tool
|    tool_stepover_percent -- percentage stepover for tool
|    tool_in_mm            -- true if tool size and stepdown are in mm
|
|  Return Values:
|     true if toolpath created OK else false
|
]]

function CreateVCarvingToolpath( name , start_depth, flat_depth, vbit_angle, vbit_dia, vbit_stepdown, tool_stepover_percent, tool_in_mm)

   -- Create tool we will use to machine vectors
   local tool = Tool(
                    "Lua VBit", 
                    Tool.VBIT       -- BALL_NOSE, END_MILL, VBIT
                    )
                     
   tool.InMM = tool_in_mm
   tool.ToolDia = vbit_dia
   tool.Stepdown = vbit_stepdown
   tool.Stepover = vbit_dia * (tool_stepover_percent / 100)
   tool.RateUnits = Tool.MM_SEC  -- MM_SEC, MM_MIN, METRES_MIN, INCHES_SEC, INCHES_MIN, FEET_MIN
   tool.FeedRate = 30
   tool.PlungeRate = 10
   tool.SpindleSpeed = 20000
   tool.ToolNumber = 1
   tool.VBitAngle = 90.0                -- used for vbit only
   tool.ClearStepover = vbit_dia * (tool_stepover_percent / 100) * 2  -- used for vbit only
  
   -- we will set home position and safe z relative to material block size  
   local mtl_block = MaterialBlock()  
   local mtl_box = mtl_block.MaterialBox
   local mtl_box_blc = mtl_box.BLC
  
   -- Create object used to set home position and safez gap above material surface
   local pos_data = ToolpathPosData()
   pos_data:SetHomePosition(mtl_box_blc.x, mtl_box_blc.y, mtl_box.TRC.z + (mtl_block.Thickness * 0.2) )
   pos_data.SafeZGap = mtl_block.Thickness * 0.1

   -- Create  object used to pass vcarving options
   local vcarve_data = VCarveParameterData()
      -- start depth for toolpath
      vcarve_data.StartDepth = start_depth
      
      -- flag indicating if we are creating a flat bottomed toolpath
      vcarve_data.DoFlatBottom = flat_depth > 0.0
      
      -- cut depth for toolpath this is depth below start depth
      vcarve_data.FlatDepth = flat_depth
      
      -- if true in Aspire, project toolpath onto composite model
      vcarve_data.ProjectToolpath = false

      -- set flag indicating we are using flat tool
	  vcarve_data.UseAreaClearTool = true
      
   -- Create  object used to pass pocketing options - used for area clearance only
   local pocket_data = PocketParameterData()
      -- start depth for toolpath
      pocket_data.StartDepth = start_depth
      
      -- cut depth for toolpath this is depth below start depth
      pocket_data.CutDepth = flat_depth
      
      -- direction of cut for offet clearance - ProfileParameterData.CLIMB_DIRECTION or ProfileParameterData.CONVENTIONAL_DIRECTION - NOTE: enum from ProfileParameterData
      pocket_data.CutDirection = ProfileParameterData.CLIMB_DIRECTION
      
      -- if true use raster clearance strategy , else use offset area clearance
      pocket_data.DoRasterClearance = false
      -- angle for raster if using raster clearance
      pocket_data.RasterAngle = 0
      -- type of profile pass to perform  PocketParameterData.PROFILE_NONE , PocketParameterData.PROFILE_FIRST orPocketParameterData.PROFILE_LAST
      pocket_data.ProfilePassType = PocketParameterData.PROFILE_LAST
      
   -- Create object which can used to automatically select geometry on layers etc
   local geometry_selector = GeometrySelector() 
   
   -- if this is true we create 2d toolpaths previews in 2d view, if false we dont
   local create_2d_previews = true
   
   -- if this is true we will display errors and warning to the user
   local display_warnings = true
   
   -- if we are doing two tool pocketing define tool to use for area clearance
   local area_clear_tool = nil
   
   -- we just create a 10mm end mill
  
   area_clear_tool = Tool(
                          "Lua Clearance End Mill", 
                          Tool.END_MILL       -- BALL_NOSE, END_MILL, VBIT
                          )
                     
   area_clear_tool.InMM = true
   area_clear_tool.ToolDia = 10
   area_clear_tool.Stepdown = 3
   area_clear_tool.Stepover = 3
   area_clear_tool.RateUnits = Tool.MM_SEC  -- MM_SEC, MM_MIN, METRES_MIN, INCHES_SEC, INCHES_MIN, FEET_MIN
   area_clear_tool.FeedRate = 30
   area_clear_tool.PlungeRate = 10
   area_clear_tool.SpindleSpeed = 20000
   area_clear_tool.ToolNumber = 2
   
   -- Create our toolpath

   local toolpath_manager = ToolpathManager()
 
   local toolpath_id = toolpath_manager:CreateVCarvingToolpath(
                                              name,
                                              tool,
                                              area_clear_tool,
                                              vcarve_data,
                                              pocket_data,
                                              pos_data,
                                              geometry_selector,
                                              create_2d_previews,
                                              display_warnings
                                              )
   
   if toolpath_id  == nil  then
      DisplayMessageBox("Error creating toolpath")
      return false
   end                                                    

   return true  

end


--[[  ------------- main --------------------------------------------------  
|
|  Entry point for script
|
]]

function main()

    -- Check we have a document loaded
    local job = VectricJob()
 
    if not job.Exists then
       DisplayMessageBox("No job loaded")
       return false;  
    end
 
   local selection = job.Selection
   if selection.IsEmpty  then
       MessageBox("Please select one or more vectors to VCarve")
       return false  
    end
    
	local mtl_block = MaterialBlock()
	
    local start_depth = 0.0
    local flat_depth = mtl_block.Thickness * 0.5
    local vbit_angle = 90.0
    local tool_dia = 32.0
    local tool_stepdown = 2.5
    local tool_stepover_percent = 2.0
    local tool_in_mm = true
    
    local success = CreateVCarvingToolpath( 
                                           "Lua VCarving Toolpath", 
                                           start_depth, 
                                           flat_depth, 
                                           vbit_angle,
                                           tool_dia, 
                                           tool_stepdown, 
                                           tool_stepover_percent,
                                           tool_in_mm 
                                           )
    
    
    return success;
end     

:CreatePrismCarvingToolpath(

Top.jpg

Usage: :CreatePrismCarvingToolpath(

String name,
Tool tool,
PrismCarveParameterData prism_data,
ToolpathPosData pos_data,
GeometrySelectorgeometry_selector,
bool create_2d_preview,
bool interactive)

Creates a prism carving toolpath for the currently selected vectors.

Returns: the UUID for the toolpath created.

name(string) Name for the toolpath to be created
tool (Tool) Tool to use for the toolpath
prism_data (PrismParameterData) Settings for prism carving
pos_data (ToolpathPosData) Settings for home position, safe z etc
geometry_selector (GeometrySelector) Can be used to automatically select vectors on layers etc
create_2d_preview(bool) If true create preview vectors in 2d view
interactive(bool) If true display warnings etc to user

Example Code: CreatePrismToolpath

 from Create_Prism_CarvingToolpath.lua
 -- VECTRIC LUA SCRIPT require "strict"
 -- [[ CreatePrismToolpath 
|
|   Create a prism toolpath within the program for the currently selected vectors
|  Parameters:
|     name,                -- Name for toolpath
|     start_depth      -- Start depth for toolpath below surface of material
|    cut_depth          -- cut depth for drilling toolpath
|    vbit_angle         -- angle of vbit to use
|    vbit_dia            -- diameter of VBit  to use
|    vbit_stepdown    -- stepdown for tool
|    tool_stepover_percent -- percentage stepover for tool
|    tool_in_mm        -- true if tool size and stepdown are in mm
|
|  returns (Values:
|     true if toolpath created OK else false
|
]]
function CreatePrismToolpath( name , start_depth, cut_depth, vbit_angle,
vbit_dia, vbit_stepdown, tool_stepover_percent, tool_in_mm)
 -- Create tool we will use to machine vectors
local tool = Tool(
"Lua VBit",
Tool.VBIT      -- BALL_NOSE, END_MILL, VBIT
)




tool.InMM = tool_in_mm
===.tool.ToolDia = vbit_dia=== 
tool.Stepdown = vbit_stepdown
tool.Stepover = vbit_dia * (tool_stepover_percent or 100)
tool.RateUnits = Tool.MM_SEC -- MM_SEC, MM_MIN, METRES_MIN,                                  -- INCHES_SEC, INCHES_MIN, FEET_MIN    tool.FeedRate = 30
tool.PlungeRate = 10
tool.SpindleSpeed = 20000
tool.ToolNumber = 1
tool.VBitAngle = 90.0               -- used for vbit only
tool.ClearStepover = vbit_dia * (tool_stepover_percent or 100) * 2 -- used for vbit only
 -- Create object used to set home position and safez gap above material surface
local pos_data = ToolpathPosData()

pos_data:SetHomePosition(0, 0, 5.0)
pos_data.SafeZGap = 5.0

 -- Create  object used to pass profile options
local prism_data = PrismCarveParameterData()
 -- start depth for toolpath
prism_data.StartDepth = start_depth

 -- cut depth for toolpath this is depth below start depth
prism_data.CutDepth = cut_depth

 -- direction of cut for offet clearance (ProfileParameterData.CLIMB_DIRECTION or ProfileParameterData.CONVENTIONAL_DIRECTION ) 

::''NOTE: enum from ProfileParameterData''
prism_data.CutDirection = ProfileParameterData.CLIMB_DIRECTION

 -- calculate the minimum cut depth to fully form the bevel on the current
 -- selection with the current tool
local min_bevel_depth = prism_data:CalculateMinimumBevelDepth(tool, true)
if min_bevel_depth > cut_depth then
DisplayMessageBox(
"A prism will not be fully formed with a depth of "   cut_depth   "\r\n"
"A depth of "   min_bevel_depth   " is required to fully form the prism"
) end

 -- Create object which can be used to automatically select geometry
local geometry_selector = GeometrySelector()

 -- if this is true we create 2d toolpaths previews in 2d view, if false we dont
local create_2d_previews = true

 -- if this is true we will display errors and warning to the user
local display_warnings = true

 -- Create our toolpath

local toolpath_manager = ToolpathManager()

local toolpath_id = toolpath_manager:CreatePrismCarvingToolpath(                                               name,                                               tool,                                               prism_data,                                               pos_data,                                               geometry_selector,                                               create_2d_previews,                                               display_warnings
)

if toolpath_id  == nil  then
DisplayMessageBox("Error creating toolpath") 
return false
end

return true
end

 -- [[ main
|
|  Entry point for script
|
]]
function main()

 -- Check we have a job loaded
job = VectricJob()

if not job.Exists then
DisplayMessageBox("No job loaded")
return false;
end
local selection = job.Selection
if selection.IsEmpty  then
MessageBox("Please select one or more vectors to bevel carve")
return false
end
local start_depth = 0.0
local cut_depth = 20.0
local vbit_angle = 90.0
local tool_dia = 32.0
local tool_stepdown = 2.5
local tool_stepover_percent = 2.0
local tool_in_mm = true

local success = CreatePrismToolpath(
"Lua Prism Toolpath",                                             start_depth,                                             cut_depth,                                             vbit_angle,                                            tool_dia,                                             tool_stepdown,                                             tool_stepover_percent,                                            tool_in_mm
)
return success;



end 

:CreateFlutingToolpath()

Top.jpg

Usage::CreateFlutingToolpath(

String name,
Tool tool,
FlutingParameterDatafluting_data,
ToolpathPosData pos_data,
GeometrySelector geometry_selector,
bool create_2d_preview,
bool interactive
)

Creates a fluting toolpath for the currently selected vectors.

Returns: the UUID for the toolpath created.

name(string) Name for the toolpath to be created
tool (Tool) Tool to use for the toolpath
fluting_data (FlutingParameterData) Settings for fluting
pos_data(ToolpathPosData)Settings for home position, safe z etc
geometry_selector(GeometrySelector) Can be used to automatically select vectors on layers etc
create_2d_preview(bool) If true create preview vectors in 2d view
interactive(bool) If true display warnings etc to user


Example Code: CreateFlutingToolpath()
  -- VECTRIC LUA SCRIPT
-- Copyright 2013 Vectric Ltd.

-- Gadgets are an entirely optional add-in to Vectric's core software products. 
-- They are provided 'as-is', without any express or implied warranty, and you make use of them entirely at your own risk.
-- In no event will the author(s) or Vectric Ltd. be held liable for any damages arising from their use.

-- Permission is granted to anyone to use this software for any purpose, 
-- including commercial applications, and to alter it and redistribute it freely, 
-- subject to the following restrictions:

-- 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
-- 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
-- 3. This notice may not be removed or altered from any source distribution.

require "strict"

--[[  ----------------- CreateFlutingToolpath -----------------  
|
|   Create a drilling toolpath within the program for the currently selected vectors
|  Parameters:
|    name,               -- Name for toolpath
|    start_depth         -- Start depth for toolpath below surface of material
|    cut_depth           -- cut depth for toolpath
|    tool_dia            -- diameter of tool to use
|    tool_stepdown       -- stepdown for tool
|    tool_in_mm          -- true if tool size and stepdown are in mm
|
|  Return Values:
|     true if toolpath created OK else false
|
]]

function CreateFlutingToolpath( name , start_depth, cut_depth, tool_dia, tool_stepdown, tool_in_mm)

  -- Create tool we will use to machine vectors
  local tool = Tool(
    "Lua Ball Nose", 
    Tool.BALL_NOSE       -- BALL_NOSE, END_MILL, VBIT, THROUGH_DRILL
  )

  tool.InMM = tool_in_mm
  tool.ToolDia = tool_dia
  tool.Stepdown = tool_stepdown
  tool.Stepover = tool_dia * 0.25
  tool.RateUnits = Tool.MM_SEC  -- MM_SEC, MM_MIN, METRES_MIN, INCHES_SEC, INCHES_MIN, FEET_MIN
  tool.FeedRate = 30
  tool.PlungeRate = 10
  tool.SpindleSpeed = 20000
  tool.ToolNumber = 1
  tool.VBitAngle = 90.0                -- used for vbit only
  tool.ClearStepover = tool_dia * 0.5  -- used for vbit only


  -- Create object used to set home position and safez gap above material surface
  local pos_data = ToolpathPosData()

  pos_data:SetHomePosition(0, 0, 5.0)
  pos_data.SafeZGap = 5.0

  -- Create  object used to pass fluting options
  local fluting_data = FlutingParameterData()
  -- start depth for toolpath
  fluting_data.StartDepth = start_depth

  -- cut depth for toolpath this is depth below start depth
  fluting_data.CutDepth = cut_depth

  -- type of fluting FULL_LENGTH, RAMP_START or RAMP_START_END
  fluting_data.FluteType = FlutingParameterData.RAMP_START_END

  -- type of ramping RAMP_LINEAR, RAMP_SMOOTH
  fluting_data.RampType = FlutingParameterData.RAMP_LINEAR

  -- if true use ratio field for controling ramp length else absolute length value
  fluting_data.UseRampRatio = false

  -- length of ramp as ratio of flute length(range 0 - 1.0) (for start and end - ratio is of half length)
  fluting_data.RampRatio = 0.2

  -- length to ramp over - if UseRampRatio == false
  fluting_data.RampLength = 15

  -- if true in Aspire, project toolpath onto composite model
  fluting_data.ProjectToolpath = false

  -- Create object which can used to automatically select geometry on layers etc
  local geometry_selector = GeometrySelector() 

  -- if this is true we create 2d toolpaths previews in 2d view, if false we dont
  local create_2d_previews = true

  -- if this is true we will display errors and warning to the user
  local display_warnings = true

  -- Create our toolpath

  local toolpath_manager = ToolpathManager()

  local toolpath_id = toolpath_manager:CreateFlutingToolpath(
    name,
    tool,
    fluting_data,
    pos_data,
    geometry_selector,
    create_2d_previews,
    display_warnings
  )

  if toolpath_id  == nil  then
    DisplayMessageBox("Error creating toolpath")
    return false
  end                                                    

  return true  

end


--[[  ----------------- main ----------------- 
|
|  Entry point for script
|
]]

function main()

  -- Check we have a job loaded
  local job = VectricJob()

  if not job.Exists then
    DisplayMessageBox("No job loaded")
    return false;  
  end

  local selection = job.Selection
  if selection.IsEmpty  then
    MessageBox("Please select one or more vectors to flute")
    return false  
  end

  local start_depth = 0.0
  local cut_depth = 1.0
  local tool_dia = 1.0
  local tool_stepdown = 0.5
  local tool_in_mm = false

  local success = CreateFlutingToolpath( 
    "Lua Fluting Toolpath", 
    start_depth, 
    cut_depth, 
    tool_dia, 
    tool_stepdown, 
    tool_in_mm 
  )


  return success;
end   

:CreateRoughingToolpath()

Top.jpg

Usage: :CreateRoughingToolpath(

String name,
Tool tool,
RoughingParameterData roughing_ data,
ToolpathPosData pos_data,
GeometrySelector geometry_selector,
bool interactive) Aspire Only

Creates a roughing toolpath.

Returns: the UUID for the toolpath created. NOTE: This method is only available in Aspire

name(string) Name for the toolpath to be created
tool (Tool) Tool to use for the toolpath
roughing_data(RoughingParameterData) Settings for roughing, strategy etc
pos_data(ToolpathPosData) Settings for home position, safe z etc
geometry_selector(GeometrySelector)Can be used to automatically select vectors on layers etc
interactive(bool) If true display warnings etc to user

Example Code: CreateRoughingToolpath

From 05_Roughing_Toolpath.lua

function CreateRoughingToolpath()

 -- Toolpath name
local name = "Lua Roughing Toolpath"

 -- Metric unit parameters
local tool_dia = 6.35 -- Quarter of an inch
local tool_stepdown = 5
local tool_stepover_percent = 40

 -- Create tool we will use to machine vectors
local tool = Tool("Lua End Mill", Tool.END_MILL)

tool.InMM = true
tool.ToolDia = tool_dia
tool.Stepdown = tool_stepdown
tool.Stepover = tool_dia * (tool_stepover_percent or 100)
tool.RateUnits = Tool.MM_SEC -- MM_SEC, MM_MIN, METRES_MIN, INCHES_SEC, INCHES_MIN, FEET_MIN
tool.FeedRate = 30
tool.PlungeRate = 10
tool.SpindleSpeed = 20000
tool.ToolNumber = 1
tool.VBitAngle = 90.0               -- used for vbit only
tool.ClearStepover = tool_dia * (tool_stepover_percent or 100) -- used for vbit only
 -- we will set home position and safe z relative to material block size
local mtl_block = MaterialBlock()
local mtl_box = mtl_block.MaterialBox   local mtl_box_blc = mtl_box.BLC

 -- Create object used to set home position and safez gap above material surface
local pos_data = ToolpathPosData()
pos_data:SetHomePosition(mtl_box_blc.x, mtl_box_blc.y, mtl_box.TRC.z + (mtl_block.Thickness
* 0.2))
pos_data.SafeZGap = mtl_block.Thickness * 0.1

 -- Pocketing parameters   local start_depth = 0
local cut_depth = mtl_box.ZLength

 -- Create object used to pass roughing options
local roughing_data = RoughingParameterData() -- start depth for toolpath
roughing_data.StartDepth = start_depth

 -- cut depth for toolpath this is depth below start depth
roughing_data.CutDepth = cut_depth

 -- Machining allowance
roughing_data.MachiningAllowance = 0.0

 -- Allowance to leave on when machining (this is different from machining allowance)
roughing_data.Allowance = 0.0

 -- if true use z level roughing
roughing_data.DoZLevelRoughing = true  -- z level clearance strategy
roughing_data.ZLevelStrategy = RoughingParameterData.RASTER_X
roughing_data.ZLevelProfile = RoughingParameterData.LAST
 -- angle for raster if using raster clearance
roughing_data.RasterAngle = 0

 -- if true we ramp into pockets (always zig zag)
roughing_data.DoRamping = false  -- if ramping, distance to ramp over
roughing_data.RampDistance = 10.0

 -- Create object which can used to automatically select geometry on layers etc
local geometry_selector = GeometrySelector()

 -- if this is true we will display errors and warning to the user
local display_warnings = true

 -- Create our toolpath
local toolpath_manager = ToolpathManager()
local toolpath_id = toolpath_manager:CreateRoughingToolpath(
                                               name,
                                               tool,
                                               roughing_data,
                                               pos_data,
                                               geometry_selector,
                                               display_warnings
                                              )

if not toolpath_id then
DisplayMessageBox("Error creating toolpath") end
end 

:CreateFinishingToolpath() Aspire Only

Top.jpg

String name, Tool tool, PocketParameterData pocket_data, ToolpathPosData pos_data, GeometrySelector geometry_selector, bool create_2d_preview, bool interactive ) Creates a finishing toolpath for the currently selected vectors.

Returns: the UUID for the toolpath created. NOTE: This method is only available in Aspire

name(string) Name for the toolpath to be created tool (Tool) Tool to use for the toolpath pocket_data (PoketParameterData) Setting for pocketing depth, style etc pos_data(ToolpathPosData) Settings for home position, safe z etc geometry_selector(GeometrySelector) Can be used to automatically select vectors on layers etc create_2d_preview(bool) If true create preview vectors in 2d view interactive(bool) If true display warnings etc to user

Example Code: CreateFinishingToolpath

From 04_Finishing_Toolpath.lua
function CreateFinishingToolpath()

  -- Toolpath name
  local name = "Lua Finishing Toolpath"

  -- Metric unit parameters
  local tool_dia = 3.175 -- 8th of an inch
  local tool_stepdown = 5
  local tool_stepover_percent = 10

  -- Create tool we will use to machine vectors
  local tool = Tool("Lua Ball Nose", Tool.BALL_NOSE)

  tool.InMM = true
  tool.ToolDia = tool_dia
  tool.Stepdown = tool_stepdown
  tool.Stepover = tool_dia * (tool_stepover_percent or 100)
  tool.RateUnits = Tool.MM_SEC -- MM_SEC, MM_MIN, METRES_MIN, INCHES_SEC, INCHES_MIN, FEET_MIN
  tool.FeedRate = 30   
  tool.PlungeRate = 10
  tool.SpindleSpeed = 20000
  tool.ToolNumber = 1
  tool.VBitAngle = 90.0               -- used for vbit only
  tool.ClearStepover = tool_dia * (tool_stepover_percent or 100) -- used for vbit only
  -- we will set home position and safe z relative to material block size
  local mtl_block = MaterialBlock()
  local mtl_box = mtl_block.MaterialBox
  local mtl_box_blc = mtl_box.BLC

  -- Create object used to set home position and safez gap above material surface
  local pos_data = ToolpathPosData()
  pos_data:SetHomePosition(mtl_box_blc.x, mtl_box_blc.y, mtl_box.TRC.z +
    (mtl_block.Thickness * 0.2))
  pos_data.SafeZGap = mtl_block.Thickness * 0.1

  -- Pocketing parameters   local start_depth = 0
  local cut_depth = mtl_box.ZLength

  -- Create object used to pass pocketing options
  local pocket_data = PocketParameterData()
  -- start depth for toolpath
  pocket_data.StartDepth = start_depth

  -- cut depth for toolpath this is depth below start depth
  pocket_data.CutDepth = cut_depth

  -- direction of cut for offet clearance(ProfileParameterData.CLIMB_DIRECTION or ProfileParameterData.CONVENTIONAL_DIRECTION) 
  NOTE: enum from ProfileParameterData
  pocket_data.CutDirection = ProfileParameterData.CLIMB_DIRECTION

  -- Allowance to leave on when machining
  pocket_data.Allowance = 0.0

  -- if true use raster clearance strategy , else use offset area clearance
  pocket_data.DoRasterClearance = true  -- angle for raster if using raster clearance
  pocket_data.RasterAngle = 0
  -- type of profile pass to perform  PocketParameterData.PROFILE_NONE , PocketParameterData.PROFILE_FIRST orPocketParameterData.PROFILE_LAST
  pocket_data.ProfilePassType = PocketParameterData.PROFILE_LAST

  -- if true we ramp into pockets (always zig zag)
  pocket_data.DoRamping = false  -- if ramping, distance to ramp over
  pocket_data.RampDistance = 10.0

  -- if true in Aspire, project toolpath onto composite model
  pocket_data.ProjectToolpath = false

  -- Create object which can used to automatically select geometry on layers etc
  local geometry_selector = GeometrySelector()

  -- if this is true we create 2d toolpaths previews in 2d view, if false we dont
  local create_2d_previews = true

  -- if this is true we will display errors and warning to the user
  local display_warnings = true

  -- Create our toolpath
  local toolpath_manager = ToolpathManager()
  local toolpath_id = toolpath_manager:CreateFinishingToolpath(name, tool, pocket_data, pos_data, geometry_selector, create_2d_previews display_warnings )

  if not toolpath_id then
    DisplayMessageBox("Error creating toolpath")
  end
end 

:LoadToolpathTemplate(string template_path)

Top.jpg

Load a toolpath template from passed file.

Returns: (bool) true if template loaded OK, else false template_path (string) Full path to template file to load

Example Code:

-- VECTRIC LUA SCRIPT

require "strict"

-- [[ -------------- main ---------------------
|
|  Entry point for script
|
]]
function main()

  -- Check we have a job loaded
  
  local job = VectricJob()

  if not job.Exists then
    DisplayMessageBox("No job loaded")
    return false
  end
  
  local template_path = "c:\\temp\\TestToolpathTemplate.ToolpathTemplate"

  local toolpath_manager = ToolpathManager()
  if not toolpath_manager:LoadToolpathTemplate(template_path) then
    MessageBox("Failed to load template "   template_path)
    return false
  end

  MessageBox("Loaded template "   template_path)

  local calc_result = toolpath_manager:RecalculateAllToolpaths()
  
  if calc_result == nil then
    MessageBox("Recalculate all toolpaths failed")
  else
    MessageBox("Results from recalculate all\n"   calc_result)
  end

  return true
end

:CopyToolpathWithId( UUID id, bool insert_at_end, bool rename)

Top.jpg

Copy (duplicate) toolpath with passed id , returns copied toolpath and adds to toolpath list id (UUID) Id of toolpath to copy insert_at_end (bool) If true, new toolpath is inserted at end of list, else following original to copy rename (bool) If true, new toolpath is automatically renamed, else keeps same name


:DeleteAllToolpaths()

Deletes ALL toolpaths in job. (Revised: Feb 10, 2020)

Example Code:

  local toolpath_mgr = ToolpathManager()
        toolpath_mgr:DeleteAllToolpaths()
 

:DeleteToolpath( Toolpath toolpath)

Delete passed toolpath Note: make sure you do not refer to toolpath in script after this call! toolpath (Toolpath) Toolpath to delete


:DeleteToolpathWithId( UUID id)

Delete toolpath with passed id id(UUID)id of toolpath to delete


:Find( UUID id)

Returns: the POSITION in the list of the toolpath with hte passed id Note: nil if no toolpath with id found id(UUID)id of toolpath to find position for


:GetAt( pos)

Returns: the toolpath at the passed position

pos (POSTION) current position in list


:GetGroupToolpathWithIndex( UUID id, integer index)

Top.jpg

Returns: (the nth toolpath of the passed group id. Toolpaths created together such as the two toolpaths from a flat bottom vcarve with two tools share a unique groupid property.

id (UUID) Id of toolpath group
index (integer)Index (inrange 0 to n to 1) of toolpath in group to return

:GetNext( pos)

Returns: Both the toolpath at the current position ANDa new value for position pointing to the next item in the list (or nil if at end of list)

pos (POSTION) current position in list
Example Code:
Note: GetNext(pos) is returning two values
    local pos = uuid_list:GetHeadPosition()
	local id
	while pos ~= nil do
	  id, pos = uuid_list:GetNext(pos)
      DO SOMETHING WITH ID
	end

:GetNumberOfToolpathsInGroup( UUID id)

Returns: (the number of toolpaths which have the passed group id. Toolpaths created together such as the two toolpaths from a flat bottom vcarve with two tools share a unique groupid property. id (UUID) Id of toolpath group to count members for


:GetPrev( pos)

Top.jpg

Returns: Both the toolpath at the current position ANDa new value for position, pointing to the previous item in the list (or nil if at start of list)

pos (POSTION) current position in list


:GetSelectedToolpath()

Returns: the currently selected toolpath or nil if no toolpath currently selected


:GetHeadPosition()

Returns: (POSITION) a variable to allow access to the head of the list of toolpaths


:GetTailPosition()

Returns: (POSITION) a variable to allow access to the tail of the list of toolpaths


:RecalculateAllToolpaths()

Top.jpg

Recalculate all toolpaths in the job.

Returns: a string containing a list of all the toolpaths recalculated if it succeeds, else nil.

WARNING: Recalculating all toolpaths will destroy the original toolpaths and create new ones with the same ID.

Do not try and reuse a toolpath variable after this call. See

Example Code:

  local toolpath_mgr = ToolpathManager()
  DisplayMessageBox(toolpath_mgr:RecalculateAllToolpaths())
 

:RecalculateToolpath(Toolpath toolpath )

For information on how to retrieve a specific toolpath after it has been recalculated.

For Example:

local orig_id = luaUUID()
orig_id:SetId(toolpath.Id)
local recalced_toolpath = nil
if toolpath_manager:RecalculateToolpath(toolpath) then
  local recalced_pos = toolpath_manager:Find(orig_id.RawId)
  if recalced_pos == nil then
    MessageBox("Failed to find toolpath after calculation")
    return false
  else
    recalced_toolpath = toolpath_manager:GetAt(recalced_pos)
  end -- if end
end -- if end

:RecalculateToolpath( Toolpath toolpath)

Top.jpg

Recalculates passed toolpath.

Returns: (bool) true if toolpath recalculated ok toolpath (Toolpath) Toolpath to recalculate

WARNING: The passed toolpath is invalid after this call as a new toolpath with the same id is created internally. If you wish to continue accesing the toolpath after recalculating, save its id BEFORE calling:RecalculateToolpath() and then use:Find(id) to find the position of the recalculated toolpath and use:GetAt(position) to return the recalculated toolpath.

:SaveToolpathAsTemplate( Toolpath toolpath, string template_path)

Save a toolpath as a template to passed file.

Returns: (bool) true if template saved, else false. If passed toolpath is part of a group (Note: flat bottom vcarving) all toolpaths in group are saved to the template toolpath (Toolpath) Toolpath to save as a template template_path (string) Full path to template file to save


:SaveVisibleToolpathsAsTemplate( string template_path)

Save all visible toolpaths as a template to passed file.

Returns: (bool) true if template saved, else false. template_path (string) Full path to template file to save


:ToolpathModified( Toolpath toolpath)

Top.jpg

This method must be called if parameters for a toolpath are modified from script.

For Example:
tool parameters are changed. If this method is not called the ui will not show the changes you have made.
toolpath (Toolpath) Toolpath which has been modified 

:ToolpathWithNameExists( string name)

Returns: (bool) true if there is one or more existing toolpaths with passed name

name (string) Toolpath name to check for id (UUID) Id of toolpath to delete


:UndrawAllToolpath()

Undraw (set visibility to false) ALL toolpaths in job.


:SetAllToolpathsVisibility( bool visibility)

Set visibility for all toolpaths in job.

visibility (bool) true to draw all toolpaths, false to stop drawing them


Back.jpg

References

Please Note: The base material for the contents found in this WiKi was sourced from Vectric Lua Interface for Gadgets, version 10.0, published August 21, 2019. by Vectric Ltd. Most current document from Vertric can be downloaded at Vertric Developer Information