def arc(self, dir, x, y, z, i, j, k, r): self.rapid_flag = False if x == None: x = self.x if y == None: y = self.y if z == None: z = self.z area.set_units(0.05) curve = area.Curve() curve.append(area.Point(self.x, self.y)) curve.append(area.Vertex(dir, area.Point(x, y), area.Point(i, j))) curve.UnFitArcs() for span in curve.GetSpans(): self.add_line(Point(span.p.x, span.p.y, z), Point(span.v.p.x, span.v.p.y, z)) self.x = x self.y = y self.z = z
import sys sys.path.insert(0, '/home/danfalck/git3/free-cad/Mod/CNC/posts') sys.path.insert(0, '/home/danfalck/git3/free-cad/Mod/CNC/machining_ops') import math import area import kurve_funcs area.set_units(1) from nc import * import emc2b output('/home/danfalck/git3/free-cad/Mod/CNC/tmp/fctest.tap') absolute() metric() set_plane(0) workplane(1) comment('tool change to 4.7752 mm Carbide End Mill') tool_change(id=4) spindle(7000) feedrate_hv(840, 100) flush_nc() clearance = float(5) rapid_safety_space = float(2) start_depth = float(0) step_down = float(1) final_depth = float(-1) tool_diameter = float(4.7752) cutting_edge_angle = float(0) #absolute() mode roll_radius = float(2) offset_extra = 0 comment('Sketch') curve = area.Curve()
def load(self, nc_filepath): # this converts the G1s in an NC file into arcs with G2 or G3 pattern_main = re.compile( '([(!;].*|\s+|[a-zA-Z0-9_:](?:[+-])?\d*(?:\.\d*)?|\w\#\d+|\(.*?\)|\#\d+\=(?:[+-])?\d*(?:\.\d*)?)' ) self.lines = [] self.length = 0.0 file = open(nc_filepath, 'r') arc = 0 self.rapid = False curx = None cury = None curz = None while (True): line = file.readline().rstrip() if len(line) == 0: break move = False x = None y = None z = None i = None j = None words = pattern_main.findall(line) for word in words: word = word.upper() if word == 'G1' or word == 'G01': self.rapid = False arc = 0 elif word == 'G2' or word == 'G02': self.rapid = False arc = -1 elif word == 'G3' or word == 'G03': self.rapid = False arc = 1 elif word == 'G0' or word == 'G00': self.rapid = True arc = 0 elif word[0] == 'X': x = eval(word[1:]) move = True elif word[0] == 'Y': y = eval(word[1:]) move = True elif word[0] == 'Z': z = eval(word[1:]) move = True elif word[0] == 'I': i = float(eval(word[1:])) elif word[0] == 'J': j = float(eval(word[1:])) elif word[0] == 'T': self.current_tool = eval(word[1:]) if (curx != None) and (cury != None) and (curz != None): self.add_line(Point(curx, cury, curz), Point(curx, cury, 30.0)) curz = 30.0 elif word[0] == ';': break if move: if (curx != None) and (cury != None) and (curz != None): newx = curx newy = cury newz = curz if x != None: newx = float(x) if y != None: newy = float(y) if z != None: newz = float(z) if arc != 0: area.set_units(0.05) curve = area.Curve() curve.append(area.Point(curx, cury)) # next 4 lines were for Bridgeport. # this only works for LinuxCNC now #if (newx > curx) != (arc > 0): # j = -j #if (newy > cury) != (arc < 0): # i = -i curve.append( area.Vertex(arc, area.Point(newx, newy), area.Point(curx + i, cury + j))) curve.UnFitArcs() for span in curve.GetSpans(): self.add_line(Point(span.p.x, span.p.y, newz), Point(span.v.p.x, span.v.p.y, newz)) else: self.add_line(Point(curx, cury, curz), Point(newx, newy, newz)) if x != None: curx = float(x) if y != None: cury = float(y) if z != None: curz = float(z) for line in self.lines: self.length += line.Length() file.close() self.rewind()
def load(self, nc_filepath): # this converts the G1s in an NC file into arcs with G2 or G3 pattern_main = re.compile('([(!;].*|\s+|[a-zA-Z0-9_:](?:[+-])?\d*(?:\.\d*)?|\w\#\d+|\(.*?\)|\#\d+\=(?:[+-])?\d*(?:\.\d*)?)') self.lines = [] self.length = 0.0 file = open(nc_filepath, 'r') arc = 0 self.rapid = False curx = None cury = None curz = None while(True): line = file.readline().rstrip() if len(line)== 0: break move = False x = None y = None z = None i = None j = None words = pattern_main.findall(line) for word in words: word = word.upper() if word == 'G1' or word == 'G01': self.rapid = False arc = 0 elif word == 'G2' or word == 'G02': self.rapid = False arc = -1 elif word == 'G3' or word == 'G03': self.rapid = False arc = 1 elif word == 'G0' or word == 'G00': self.rapid = True arc = 0 elif word[0] == 'X': x = eval(word[1:]) move = True elif word[0] == 'Y': y = eval(word[1:]) move = True elif word[0] == 'Z': z = eval(word[1:]) move = True elif word[0] == 'I': i = float(eval(word[1:])) elif word[0] == 'J': j = float(eval(word[1:])) elif word[0] == 'T': self.current_tool = eval(word[1:]) if (curx != None) and (cury != None) and (curz != None): self.add_line(Point(curx, cury, curz ), Point(curx, cury, 30.0)) curz = 30.0 elif word[0] == ';' : break if move: if (curx != None) and (cury != None) and (curz != None): newx = curx newy = cury newz = curz if x != None: newx = float(x) if y != None: newy = float(y) if z != None: newz = float(z) if arc != 0: area.set_units(0.05) curve = area.Curve() curve.append(area.Point(curx, cury)) # next 4 lines were for Bridgeport. # this only works for LinuxCNC now #if (newx > curx) != (arc > 0): # j = -j #if (newy > cury) != (arc < 0): # i = -i curve.append(area.Vertex(arc, area.Point(newx, newy), area.Point(curx+i, cury+j))) curve.UnFitArcs() for span in curve.GetSpans(): self.add_line(Point(span.p.x, span.p.y, newz), Point(span.v.p.x, span.v.p.y, newz)) else: self.add_line(Point(curx, cury, curz), Point(newx, newy, newz)) if x != None: curx = float(x) if y != None: cury = float(y) if z != None: curz = float(z) for line in self.lines: self.length += line.Length() file.close() self.rewind()
# coding=CP1252 #English language or it's variant detected in Microsoft Windows import sys sys.path.insert(0,'C:\\Dev\\HeeksCAM') import math sys.path.insert(0,'C:\\Dev\\HeeksCAM/Boolean') import area area.set_units(1) from nc.nc import * from nc.emc2b import * output('C:\\Users\\Dan\\AppData\\Local\\Temp\\test.ngc') program_begin(1, 'Program 1') absolute() metric() set_plane(0) #(3 mm Slot Cutter) tool_defn( 1, '3 mm Slot Cutter', {'corner radius':0, 'cutting edge angle':0, 'cutting edge height':12, 'diameter':3, 'flat radius':0, 'material':1, 'tool length offset':127, 'type':3, 'name':'3 mm Slot Cutter'}) #(4 mm Drill Bit) tool_defn( 2, '4 mm Drill Bit', {'corner radius':0, 'cutting edge angle':59, 'cutting edge height':50.8, 'diameter':4, 'flat radius':0, 'material':1, 'tool length offset':100, 'type':0, 'name':'4 mm Drill Bit'}) #(6 mm Slot Cutter) tool_defn( 3, '6 mm Slot Cutter', {'corner radius':0, 'cutting edge angle':0, 'cutting edge height':30, 'diameter':6, 'flat radius':0, 'material':1, 'tool length offset':100, 'type':3, 'name':'6 mm Slot Cutter'}) program_end()
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * #* USA * #* * #*************************************************************************** ''' This script requires that heekscnc be installed. Sorry, it's linux centric for now. ''' import sys sys.path.insert(0,'/usr/lib/heekscnc/') from nc.nc import * import nc.centroid1 import kurve_funcs import area area.set_units(25.4) ####################################################### # drilling function def drillholes(holeList,paramaters,keepdrilling=False): feedrate_hv(paramaters['verticalfeedrate'],paramaters['horizontalfeedrate']) #x, y = holeList z=0 depth=paramaters['depth'] standoff=paramaters['standoff'] dwell=paramaters['dwell'] peck_depth=paramaters['peck_depth'] retract_mode=paramaters['retract_mode'] spindle_mode=paramaters['spindle_mode'] for i in holeList: x,y = i[0],i[1]