Example Toolpath Code

From SDK
Revision as of 11:45, 1 September 2023 by WikiSysop (talk | contribs)
Jump to navigation Jump to search
Back.jpg

These are Code Examples for toolpaths.


Pocketing Toolpaths

CreatePocketingToolpath by Selection

Create a Pocketing toolpath within the program for the currently selected vectors.

 function CreatePocketingToolpath(name, start_depth, cut_depth, tool_dia, tool_stepdown, tool_stepover_percent, tool_in_mm)
--[[ ------------ 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


-- 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,...
  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
-- 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 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 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
-- if we are doing two tool pocketing define tool to use for area clearance
  local area_clear_tool = nill
-- 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..
  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
-- 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 == nill then
     DisplayMessageBox("Error creating toolpath")
     return false
  end -- if end
  return true
end -- function end

CreatePocketingToolpath by Named Layer

Create a Pocketing toolpath within the program for the named layer.

 function CreateLayerPocketingToolpath(layer_name, name, start_depth, cut_depth)
  local caller = " - " .. name
  if Milling.Pocket then
    local selection = Milling.job.Selection  -- clear current selection
          selection:Clear()
  -- get layer
    local layer = Milling.job.LayerManager:FindLayerWithName(layer_name)
    if layer == nil then
      StatusMessage("Error", "Pocketing Toolpath", "No layer found with name = "   .. layer_name, " (4601)" .. caller, 165)
      return false
    end
  -- select all closed vectors on the layer
    if not SelectVectorsOnLayer(layer, selection, true, false, true) then
      StatusMessage("Error", "Pocketing Toolpath", "No closed vectors found on layer " .. layer_name , "(4602)" .. caller, 165)
      return false
    end
   -- Create tool we will use to machine vectors
    local tool = Tool(MillTool2.Name, Tool.END_MILL)    -- BALL_NOSE, END_MILL, VBIT
          tool.InMM = MillTool2.InMM            -- tool_in_mm
          tool.ToolDia = MillTool2.ToolDia         -- tool_dia
          tool.Stepdown = MillTool2.Stepdown        -- tool_stepdown
          tool.Stepover = MillTool2.Stepover        -- tool_dia * (tool_stepover_percent / 100)
          tool.RateUnits = MillTool2.RateUnits       -- Tool.MM_SEC     -- MM_SEC, MM_MIN, METRES_MIN, INCHES_SEC, INCHES_MIN, FEET_MIN
          tool.FeedRate = MillTool2.FeedRate        -- 30
          tool.PlungeRate = MillTool2.PlungeRate      -- 10
          tool.SpindleSpeed = MillTool2.SpindleSpeed    -- 20000
          tool.ToolNumber = MillTool2.ToolNumber      -- 1
      --  tool.VBit_Angle = MillTool.VBit_Angle        -- 90.0            -- used for vbit only
      --  tool.ClearStepover = MillTool.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 offset 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 = false --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 = 1.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 don't
    local create_2d_previews = true
   -- if this is true we will display errors and warning to the user
    local display_warnings =  true -- false --
   -- if we are doing two tool pocketing define tool to use for area clearance
    local area_clear_tool = nil
    if Milling.Clearning then
   -- we just create a tool twice as large for testing here
    area_clear_tool = Tool(
                          MillTool3.Name,
                          Tool.END_MILL       -- BALL_NOSE, END_MILL, VBIT
                          )
     area_clear_tool.InMM = MillTool3.InMM       -- tool_in_mm
     area_clear_tool.ToolDia = MillTool3.ToolDia    -- tool_dia * 2
     area_clear_tool.Stepdown = MillTool3.Stepdown   -- tool_stepdown * 2
     area_clear_tool.Stepover = MillTool3.Stepover   -- tool_dia * 2 *(tool_stepover_percent / 100)
     area_clear_tool.RateUnits = MillTool3.RateUnits  -- Tool.MM_SEC  -- MM_SEC, MM_MIN, METRES_MIN, INCHES_SEC, INCHES_MIN, FEET_MIN
     area_clear_tool.FeedRate = MillTool3.FeedRate      -- 30
     area_clear_tool.PlungeRate = MillTool3.PlungeRate    -- 10
     area_clear_tool.SpindleSpeed = MillTool3.SpindleSpeed  -- 20000
     area_clear_tool.ToolNumber = MillTool3.ToolNumber    -- 1
    end
     -- area_clear_tool.VBit_Angle = Carrier.MillTool3.VBit_Angle      -- 90.0 -- used for vbit only
     -- area_clear_tool.ClearStepover = Carrier.MillTool3.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
      StatusMessage("Error", "Milling Settings", "Unable to create toolpath.", "(4603)" .. caller, 165)
      return false
    end -- if end 
  end -- if end 
  return true
end -- function end 



Drilling Toolpath by Selection

Create a drilling toolpath within the program for the currently selected vectors.

 function CreateDrillingToolpath(name, start_depth, cut_depth, retract_gap, 
                                          tool_dia, tool_stepdown, tool_in_mm)
--[[ ------- CreateDrillingToolpath --------------------------------------------------
||
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 drilling toolpath
| retract_gap -- distance to retract above surface for pecks
| tool_dia -- diameter of drill 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
|
]]
-- 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
-- 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 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 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: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 -- if end
  return true
end -- function end
Back.jpg

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