Esempio n. 1
0
	def appendBurn(self, app, block):
		x0 = self.fromMm("PosX")
		y0 = self.fromMm("PosY")
		movefeed = app.cnc["cutfeed"]
		burntime = self["Burn time"]
		burnpower = self["Burn power"]
		block.append(CNC.grapid(x=x0, y=y0))
		block.append("g1 m3 %s" % (CNC.fmt('s', burnpower)))
		block.append("g4 %s" % (CNC.fmt('p', burntime)))
		block.append("m5")
Esempio n. 2
0
 def appendBurn(self, app, block):
     x0 = self.fromMm("PosX")
     y0 = self.fromMm("PosY")
     movefeed = app.cnc["cutfeed"]
     burntime = self["Burn time"]
     burnpower = self["Burn power"]
     block.append(CNC.grapid(x=x0, y=y0))
     block.append("g1 m3 %s" % (CNC.fmt('s', burnpower)))
     block.append("g4 %s" % (CNC.fmt('p', burntime)))
     block.append("m5")
Esempio n. 3
0
    def generate(self,
                 board_width,
                 board_height,
                 number_of_pieces,
                 random_seed=0,
                 tap_shape='basic',
                 threshold=3.0):
        blocks = []
        block = Block(self.name)
        random.seed(random_seed)
        Arc.reset_used_arcs()
        Arc.set_diff_threshold(threshold)
        puzzle_cuts = self.__class__.make_puzzle_cuts(board_width,
                                                      board_height,
                                                      number_of_pieces,
                                                      tap_shape, threshold)

        # Draw puzzle cuts
        x = 0
        y = 0
        for i in range(0, int(self.thickness / self.step_z)):
            for cut in puzzle_cuts:
                block.append(CNC.zsafe())
                block.append(CNC.grapid(x + cut[0].x, y + cut[0].y))
                block.append(CNC.zenter(0.0))
                block.append(CNC.fmt("f", self.cut_feed))
                block.append(CNC.zenter(-(i + 1) * self.step_z))
                for arc in cut:
                    if arc.r:
                        block.append(
                            CNC.garc(arc.direction,
                                     x + arc.x,
                                     y + arc.y,
                                     r=arc.r))

        blocks.append(block)

        # Draw border
        block = Block(self.name + "_border")

        block.append(CNC.zsafe())
        block.append(CNC.grapid(x, y))

        for i in range(0, int(self.thickness / self.step_z)):
            block.append(CNC.fmt("f", self.cut_feed))
            block.append(CNC.zenter(-(i + 1) * self.step_z))
            block.append(CNC.gline(x + board_width, y))
            block.append(CNC.gline(x + board_width, y + board_height))
            block.append(CNC.gline(x, y + board_height))
            block.append(CNC.gline(x, y))

        block.append(CNC.zsafe())
        blocks.append(block)

        return blocks
Esempio n. 4
0
	def calc(self,x,y,depth,peck,dwell,drillFeed,safeZforG0):
		self.safeZforG0 =float(abs(safeZforG0))
		peck=abs(float(peck))
		currentz=0.0
		self.blocks = []
		self.block = Block(self.name)
		self.block.append(CNC.grapid(x=x,y=y))
		self.block.append(CNC.grapid(z=CNC.vars["safe"]))
		self.accelerateIfNeeded(0.0,drillFeed)
		self.block.append("(entered)")
		while(currentz>depth):
			currentz-=peck
			if currentz < depth:
				currentz = depth
			kwargs={"f":float(drillFeed)}
			self.block.append(CNC.gline(None,None,float(currentz),**kwargs))
			if self.safeZforG0 >0:
				self.block.append(CNC.grapid(z=0.0+self.safeZforG0))
			else :
				self.block.append(CNC.grapid(z=CNC.vars["safe"]))
			self.block.append("g4 %s"%(CNC.fmt("p",float(dwell))))
			if currentz > depth:
				self.accelerateIfNeeded(currentz,drillFeed)
		self.block.append("(exiting)")
		self.block.append(CNC.grapid(z=CNC.vars["safe"]))
		self.blocks.append(self.block)
		return self.blocks
Esempio n. 5
0
 def getPowerLine(self, app):
     if CNC.laseradaptive:
         pwrcode = "m4"
     else:
         pwrcode = "m3"
     markpower = self["Mark power"]
     return "%s %s" % (pwrcode, CNC.fmt('s', markpower))
Esempio n. 6
0
	def getPowerLine(self, app):
		if CNC.laseradaptive:
			pwrcode = "m4"
		else:
			pwrcode = "m3"
		markpower = self["Mark power"]
		return "%s %s" % (pwrcode, CNC.fmt('s', markpower))
Esempio n. 7
0
    def create_block(self, holes, name):
        targetDepth = self.fromMm("TargetDepth")
        peck = self.fromMm("Peck")
        dwell = self["Dwell"]
        block = Block(name)
        holesCount = 0

        if self.useCustom:
            block.append("M3 S0")
        else:
            block.append(CNC.zsafe())

        for bid in holes:
            for xH, yH, zH in bid:
                holesCount += 1

                if self.useCustom:
                    block.append(
                        CNC.grapid(x=xH, y=yH) + CNC.fmt(' F', self.rFeed))
                else:
                    #block.append(CNC.zsafe()) # Moved up
                    block.append(CNC.grapid(xH, yH))

                if peck != 0:
                    z = 0
                    while z > targetDepth:
                        z = max(z - peck, targetDepth)
                        if self.useCustom:
                            block.append(
                                "( --- WARNING! Peck is not setup for laser mode --- )"
                            )
                            break
                        else:
                            block.append(CNC.zenter(zH + z))
                            block.append(CNC.zsafe())

                if self.useCustom:
                    block.append("G1 S%s" % (self.spinMax))
                    block.append(CNC.gline(x=xH, y=yH))
                else:
                    block.append(CNC.zenter(zH + targetDepth))

                # Dwell time only on last pass
                if dwell != 0:
                    block.append(CNC.gcode(4, [("P", dwell)]))

                if self.useCustom:
                    block.append("G1 S%s" % (self.spinMin))
                else:
                    block.append(CNC.zsafe())

        # Gcode Zsafe on finish
        if self.useCustom:
            block.append("M5")
        else:
            block.append(CNC.zsafe())
        return (block, holesCount)
Esempio n. 8
0
	def generate(self, board_width, board_height, number_of_pieces, random_seed = 0, tap_shape = 'basic', threshold = 3.0):
		blocks = []
		block = Block(self.name)
		random.seed(random_seed)
		Arc.reset_used_arcs()
		Arc.set_diff_threshold(threshold)
		puzzle_cuts = self.__class__.make_puzzle_cuts(board_width, board_height, number_of_pieces, tap_shape, threshold)

		
		# Draw puzzle cuts
		x = 0
		y = 0
		for i in range(0, int(self.thickness / self.step_z)):
			for cut in puzzle_cuts:
				block.append(CNC.zsafe())
				block.append(CNC.grapid(x + cut[0].x, y + cut[0].y))
				block.append(CNC.zenter(0.0))
				block.append(CNC.fmt("f", self.cut_feed))
				block.append(CNC.zenter(-(i + 1) * self.step_z))
				for arc in cut:
					if arc.r:
						block.append(CNC.garc(arc.direction, x + arc.x, y + arc.y, r=arc.r))

		blocks.append(block)

		# Draw border
		block = Block(self.name + "_border")

		block.append(CNC.zsafe())
		block.append(CNC.grapid(x, y))

		for i in range(0, int(self.thickness / self.step_z)):
			block.append(CNC.fmt("f",self.cut_feed))
			block.append(CNC.zenter(-(i + 1) * self.step_z))
			block.append(CNC.gline(x + board_width, y))
			block.append(CNC.gline(x + board_width, y + board_height))
			block.append(CNC.gline(x, y + board_height))
			block.append(CNC.gline(x, y))

		block.append(CNC.zsafe())
		blocks.append(block)

		return blocks
Esempio n. 9
0
	def execute(self, app):
		name = self["name"]
		if not name or name == "default":
			name = "Drillmark"
		marksize = self["Mark size"]
		x0 = self.fromMm("PosX")
		y0 = self.fromMm("PosY")
		marktype = self["Mark type"]
		block = Block(name + " %s diameter %s" % (marktype, CNC.fmt("", marksize)))
		self.appendBurn(app, block)
		self.appendMark(app, block)
		active = app.activeBlock()
		if active == 0:
			active = 1
		blocks = [block]
		app.gcode.insBlocks(active, blocks, _("Manual drill mark"))
		app.refresh()  # <<< refresh editor
		app.setStatus(_("Generated: MyPlugin Result"))
Esempio n. 10
0
 def execute(self, app):
     name = self["name"]
     if not name or name == "default":
         name = "Drillmark"
     marksize = self["Mark size"]
     x0 = self.fromMm("PosX")
     y0 = self.fromMm("PosY")
     marktype = self["Mark type"]
     block = Block(name + " %s diameter %s" %
                   (marktype, CNC.fmt("", marksize)))
     self.appendBurn(app, block)
     self.appendMark(app, block)
     active = app.activeBlock()
     if active == 0:
         active = 1
     blocks = [block]
     app.gcode.insBlocks(active, blocks, _("Manual drill mark"))
     app.refresh()  # <<< refresh editor
     app.setStatus(_("Generated: MyPlugin Result"))
Esempio n. 11
0
    def execute(self, app):
        name = self["name"]
        if not name or name == "default": name = "Default Name"
        sel_Blocks = self["Sel_Blocks"]
        #Get inputs
        x = self["X"]
        y = self["Y"]
        z = self["Z"]
        if z == "":
            z = CNC.vars["surface"]

        cutDiam = self["CutDiam"]
        cutRadius = cutDiam / 2.0
        if self["endmill"]:
            self.master["endmill"].makeCurrent(self["endmill"])
        toolDiam = CNC.vars["diameter"]
        #Radio = self["RadioHelix"]
        pitch = self["Pitch"]
        Depth = self["Depth"]
        Mult_F_Z = self["Mult_Feed_Z"]
        helicalCut = self["HelicalCut"]
        clearanceEntry = self["ClearanceEntry"]
        clearanceExit = self["ClearanceExit"]
        clearance = clearanceEntry
        entry = self["Entry"]
        returnToSafeZ = self["ReturnToSafeZ"]

        toolDiam = CNC.vars['diameter']
        toolRadius = toolDiam / 2.0
        Radio = cutRadius - toolRadius
        if (Radio < 0): Radio = 0

        toolDiam = CNC.vars['diameter']
        toolRadius = toolDiam / 2.0
        Radio = cutRadius - toolRadius

        if clearanceEntry == "":
            clearanceEntry = 0
        if clearanceExit == "":
            clearanceExit = 0

        if helicalCut == "Helical Cut":
            turn = 2
            p = "HelicalCut "
        elif helicalCut == "Internal Right Thread":
            turn = 2
            p = "IntRightThread "
        elif helicalCut == "Internal Left Thread":
            turn = 3
            p = "IntLeftThread "
        elif helicalCut == "External Right Thread":
            Radio = cutRadius + toolRadius
            turn = 2
            p = "ExtRightThread "
        elif helicalCut == "External Left Thread":
            Radio = cutRadius + toolRadius
            turn = 3
            p = "ExtLeftThread "

# 		------------------------------------------------------------------------------------------------------------------
#Check inputs
        if sel_Blocks == 0:
            if x == "" or y == "":
                app.setStatus(
                    _("If block selected false, please make a value of x"))
                return

        elif helicalCut == "":
            app.setStatus(_("Helical Abort: Please select helical type"))
            return

        elif cutDiam < toolDiam or cutDiam == "":
            app.setStatus(
                _("Helical Abort: Helix diameter must be greater than the end mill"
                  ))
            return

        elif cutDiam <= 0:
            app.setStatus(_("Helical Abort: Helix diameter must be positive"))
            return

        elif pitch <= 0 or pitch == "":
            app.setStatus(_("Helical Abort: Drop must be greater than 0"))
            return

        elif Mult_F_Z <= 0 or Mult_F_Z == "":
            app.setStatus(
                _("Helical Abort: Z Feed Multiplier must be greater than 0"))
            return

        elif entry == "":
            app.setStatus(
                _("Helical Abort: Please selecte Entry and Exit type"))
            return

        elif clearanceEntry < 0 or clearanceEntry == "":
            app.setStatus(
                _("Helical Abort: Entry Edge Clearence may be positive"))
            return

        elif clearanceExit < 0 or clearanceExit == "":
            app.setStatus(
                _("Helical Abort: Exit Edge Clearence may be positive"))
            return
# 		------------------------------------------------------------------------------------------------------------------
#Initialize blocks that will contain our gCode
        blocks = []
        #block = Block(name)
        block = Block(p + str(cutDiam) + " Pitch " + str(pitch) + " Bit " +
                      str(toolDiam) + " depth " + str(Depth))

        cutFeed = CNC.vars[
            "cutfeedz"]  #<<< Get cut feed Z for the current material
        cutFeedMax = CNC.vars[
            "cutfeed"]  #<<< Get cut feed XY for the current material
        # 		------------------------------------------------------------------------------------------------------------------
        # Get selected blocks from editor
        selBlocks = app.editor.getSelectedBlocks()
        if not selBlocks:
            app.editor.selectAll()
            selBlocks = app.editor.getSelectedBlocks()

        if not selBlocks:
            if sel_Blocks == 1:
                app.setStatus(_("Helical abort: Please select some path"))
                return
# 		------------------------------------------------------------------------------------------------------------------
# Get selected blocks from editor
        if sel_Blocks == 1:
            selBlocks = app.editor.getSelectedBlocks()
            if not selBlocks:
                app.editor.selectAll()
                selBlocks = app.editor.getSelectedBlocks()

            #Get all segments from gcode
            allSegments = self.extractAllSegments(app, selBlocks)

            #Create holes locations
            allHoles = []
            for bidSegment in allSegments:
                if len(bidSegment) == 0:
                    continue

                bidHoles = []
                for idx, anchor in enumerate(bidSegment):
                    if idx == 2:
                        newHolePoint = (anchor[0][0], anchor[0][1],
                                        anchor[0][2])
                        bidHoles.append(newHolePoint)

                #Add bidHoles to allHoles
                allHoles.append(bidHoles)

# 		------------------------------------------------------------------------------------------------------------------
            holesCount = 0
            for bid in allHoles:
                for xH, yH, zH in bid:
                    x = xH
                    y = yH

# 		------------------------------------------------------------------------------------------------------------------
#		 Init: Adjust feed and rapid move to Z safe

        if Mult_F_Z is "":
            Mult_F_Z = 1

        if Mult_F_Z == 0:
            Mult_F_Z = 1

        if Mult_F_Z * cutFeed > cutFeedMax:
            cutFeed = cutFeedMax
        else:
            cutFeed = cutFeed * Mult_F_Z

        block.append(CNC.zsafe(
        ))  #<<< Move rapid Z axis to the safe height in Stock Material

        #		 Move rapid to X and Y coordinate
        if helicalCut == "Helical Cut" or helicalCut == "Internal Right Thread" or helicalCut == "Internal Left Thread":
            if entry == "Center":
                block.append(CNC.grapid(x, y))
            else:
                block.append(CNC.grapid(x - Radio + clearance, y))

        if helicalCut == "External Right Thread" or helicalCut == "External Left Thread":
            if entry == "Center":
                clearance = 0.0
            block.append(CNC.grapid(x - Radio - clearance, y))

        #cutFeed = int(cutFeed)
        block.append(CNC.fmt("f", cutFeed))  #<<< Set cut feed
        #	block.append(CNC.gline(x,y)
        #    while (z < 1):
        block.append(CNC.zenter(z))
        block.append(CNC.gline(x - Radio, y))
        #	cutFeed = int((CNC.vars["cutfeed"]	+ CNC.vars["cutfeedz"])/2)	#<<< Get cut feed for the current material

        #cutFeed = int(cutFeed)
        block.append(CNC.fmt("F", cutFeed))  #<<< Set cut feed

        #-----------------------------------------------------------------------------------------------------
        #	Uncomment for first flat pass
        if helicalCut == "Helical Cut":
            block.append(
                CNC.gcode(turn, [("X", x - Radio), ("Y", y), ("Z", z),
                                 ("I", Radio), ("J", 0)]))
#-----------------------------------------------------------------------------------------------------
        if (z < Depth):
            pitch = -pitch

            while ((z - pitch) < Depth):
                z = z - pitch
                block.append(
                    CNC.gcode(turn, [("X", x - Radio), ("Y", y), ("Z", z),
                                     ("I", Radio), ("J", 0)]))

        else:
            while ((z - pitch) >= Depth):
                z = z - pitch
                block.append(
                    CNC.gcode(turn, [("X", x - Radio), ("Y", y), ("Z", z),
                                     ("I", Radio), ("J", 0)]))

        #Target Level
        if entry == "Center":
            clearanceExit = 0.0
        clearance = clearanceExit
        alpha = round(Depth / pitch, 4) - round(Depth / pitch, 0)
        alpha = alpha * 2 * pi
        Radiox = Radio * cos(alpha)
        Radioy = Radio * sin(alpha)
        xsi = Radiox - clearance * cos(alpha)
        ysi = Radioy - clearance * sin(alpha)
        xse = Radiox + clearance * cos(alpha)
        yse = Radioy + clearance * sin(alpha)
        z = Depth

        if helicalCut == "Helical Cut":
            block.append(
                CNC.gcode(turn, [("X", x - Radio), ("Y", y), ("Z", z),
                                 ("I", Radio), ("J", 0)]))
            #Last flat pass
            block.append(
                CNC.gcode(turn, [("X", x - Radio), ("Y", y), ("Z", z),
                                 ("I", Radio), ("J", 0)]))
        elif helicalCut == "Internal Right Thread" or helicalCut == "External Right Thread":
            block.append(
                CNC.gcode(turn, [("X", x - Radiox), ("Y", y - Radioy),
                                 ("Z", z), ("I", Radio), ("J", 0)]))

        elif helicalCut == "Internal Left Thread" or helicalCut == "External Left Thread":
            block.append(
                CNC.gcode(turn, [("X", x - Radiox), ("Y", y + Radioy),
                                 ("Z", z), ("I", Radio), ("J", 0)]))

        # Exit clearance
        if helicalCut == "Internal Right Thread":
            block.append(CNC.gline(x - xsi, y - ysi))
        elif helicalCut == "Internal Left Thread":
            block.append(CNC.gline(x - xsi, y + ysi))
        if helicalCut == "External Right Thread":
            block.append(CNC.gline(x - xse, y - yse))
        elif helicalCut == "External Left Thread":
            block.append(CNC.gline(x - xse, y + yse))

        # Return to Z Safe
        if returnToSafeZ == 1:
            if helicalCut == "Helical Cut" or helicalCut == "Internal Right Thread" or helicalCut == "Internal Left Thread":
                if entry == "Center":
                    block.append(CNC.gline(x, y))
            block.append(CNC.zsafe())

        blocks.append(block)
        active = app.activeBlock()
        app.gcode.insBlocks(
            active, blocks, "Helical_Descent inserted"
        )  #<<< insert blocks over active block in the editor
        app.refresh()  #<<< refresh editor
        app.setStatus(
            _("Generated: Helical_Descent Result"))  #<<< feed back result
Esempio n. 12
0
	def execute(self, app):
		name = self["name"]
		if not name or name=="default": name="Default Name"
		sel_Blocks = self["Sel_Blocks"]
		#Get inputs
		x = self["X"]
		y = self["Y"]
		z = self["Z"]
		if z == "":
			z=CNC.vars["surface"]

		cutDiam = self["CutDiam"]
		cutRadius = cutDiam/2.0
		if self["endmill"]:
			self.master["endmill"].makeCurrent(self["endmill"])
		toolDiam = CNC.vars["diameter"]
		#Radio = self["RadioHelix"]
		pitch = self["Pitch"]
		Depth = self["Depth"]
		Mult_F_Z = self["Mult_Feed_Z"]
		helicalCut = self["HelicalCut"]
		clearanceEntry = self["ClearanceEntry"]
		clearanceExit = self["ClearanceExit"]
		clearance = clearanceEntry
		entry = self["Entry"]
		returnToSafeZ = self["ReturnToSafeZ"]

		toolDiam = CNC.vars['diameter']
		toolRadius = toolDiam/2.0
		Radio = cutRadius - toolRadius
		if(Radio < 0): Radio = 0

		toolDiam = CNC.vars['diameter']
		toolRadius = toolDiam/2.0
		Radio = cutRadius - toolRadius

		if clearanceEntry =="":
			clearanceEntry =0 
		if clearanceExit =="":
			clearanceExit =0 

		if helicalCut == "Helical Cut":
			turn = 2
			p="HelicalCut "
		elif helicalCut == "Internal Right Thread":
			turn = 2
			p= "IntRightThread "
		elif helicalCut == "Internal Left Thread":
			turn = 3
			p= "IntLeftThread "
		elif helicalCut == "External Right Thread":
			Radio = cutRadius + toolRadius
			turn = 2
			p= "ExtRightThread "
		elif helicalCut == "External Left Thread":
			Radio = cutRadius + toolRadius
			turn = 3
			p= "ExtLeftThread "

# 		------------------------------------------------------------------------------------------------------------------		
		#Check inputs
		if sel_Blocks == 0:
			if x == "" or y == "" :
				app.setStatus(_("If block selected false, please make a value of x"))
				return

		elif helicalCut == "":
			app.setStatus(_("Helical Abort: Please select helical type"))
			return

		elif cutDiam < toolDiam or cutDiam == "":
			app.setStatus(_("Helical Abort: Helix diameter must be greater than the end mill"))
			return

		elif cutDiam <= 0:
			app.setStatus(_("Helical Abort: Helix diameter must be positive"))
			return

		elif pitch <= 0 or pitch =="":
			app.setStatus(_("Helical Abort: Drop must be greater than 0"))
			return

		elif Mult_F_Z <= 0 or Mult_F_Z == "":
			app.setStatus(_("Helical Abort: Z Feed Multiplier must be greater than 0"))
			return

		elif entry == "":
			app.setStatus(_("Helical Abort: Please selecte Entry and Exit type"))
			return

		elif clearanceEntry < 0 or clearanceEntry == "":
			app.setStatus(_("Helical Abort: Entry Edge Clearence may be positive"))
			return

		elif clearanceExit < 0 or clearanceExit == "":
			app.setStatus(_("Helical Abort: Exit Edge Clearence may be positive"))
			return
# 		------------------------------------------------------------------------------------------------------------------		
		#Initialize blocks that will contain our gCode
		blocks = []
		#block = Block(name)
		block = Block( p + str(cutDiam) + " Pitch " + str(pitch) + " Bit " + str(toolDiam) + " depth " + str(Depth))
		
		cutFeed = CNC.vars["cutfeedz"]	#<<< Get cut feed Z for the current material
		cutFeedMax = CNC.vars["cutfeed"] #<<< Get cut feed XY for the current material
# 		------------------------------------------------------------------------------------------------------------------
		# Get selected blocks from editor
		selBlocks = app.editor.getSelectedBlocks()
		if not selBlocks:
			app.editor.selectAll()
			selBlocks = app.editor.getSelectedBlocks()

		if not selBlocks:
			if sel_Blocks == 1:
				app.setStatus(_("Helical abort: Please select some path"))
				return
# 		------------------------------------------------------------------------------------------------------------------
		# Get selected blocks from editor
		if sel_Blocks == 1:
			selBlocks = app.editor.getSelectedBlocks()
			if not selBlocks:
				app.editor.selectAll()
				selBlocks = app.editor.getSelectedBlocks()

			#Get all segments from gcode
			allSegments = self.extractAllSegments(app,selBlocks)

			#Create holes locations
			allHoles=[]
			for bidSegment in allSegments:
				if len(bidSegment)==0:
					continue

				bidHoles = []
				for idx, anchor in enumerate(bidSegment):
					if idx ==2:
						newHolePoint = (anchor[0][0],anchor[0][1],anchor[0][2])
						bidHoles.append(newHolePoint)


				#Add bidHoles to allHoles
				allHoles.append(bidHoles)

# 		------------------------------------------------------------------------------------------------------------------
			holesCount = 0
			for bid in allHoles:
				for xH,yH,zH in bid:
					x = xH
					y = yH

# 		------------------------------------------------------------------------------------------------------------------
#		 Init: Adjust feed and rapid move to Z safe 
		
		if Mult_F_Z is"":
			Mult_F_Z = 1

		if Mult_F_Z == 0:
			Mult_F_Z = 1
	
		if Mult_F_Z * cutFeed > cutFeedMax:
			cutFeed = cutFeedMax
		else:
			cutFeed = cutFeed*Mult_F_Z

		block.append(CNC.zsafe()) 			#<<< Move rapid Z axis to the safe height in Stock Material

#		 Move rapid to X and Y coordinate
		if helicalCut == "Helical Cut" or helicalCut == "Internal Right Thread" or helicalCut == "Internal Left Thread":
			if entry == "Center":
				block.append(CNC.grapid(x,y))
			else:
				block.append(CNC.grapid(x-Radio+clearance ,y))

		if helicalCut == "External Right Thread" or helicalCut == "External Left Thread":
			if entry == "Center":
				clearance = 0.0
			block.append(CNC.grapid(x-Radio-clearance ,y))

		#cutFeed = int(cutFeed)
		block.append(CNC.fmt("f",cutFeed))	#<<< Set cut feed
	#	block.append(CNC.gline(x,y)
	#    while (z < 1):
		block.append(CNC.zenter(z))
		block.append(CNC.gline(x-Radio,y))
	#	cutFeed = int((CNC.vars["cutfeed"]	+ CNC.vars["cutfeedz"])/2)	#<<< Get cut feed for the current material

		#cutFeed = int(cutFeed)
		block.append(CNC.fmt("F",cutFeed))	#<<< Set cut feed
		

#-----------------------------------------------------------------------------------------------------
	#	Uncomment for first flat pass
		if helicalCut == "Helical Cut":
			block.append(CNC.gcode(turn, [("X",x-Radio),("Y",y),("Z", z),("I",Radio), ("J",0)]))
#-----------------------------------------------------------------------------------------------------
		if (z < Depth):
			pitch = -pitch

			while ((z-pitch) < Depth) :
				z = z-pitch
				block.append(CNC.gcode(turn, [("X",x-Radio),("Y",y),("Z", z),("I",Radio), ("J",0)]))

		else:
			while ((z-pitch) >= Depth) :
				z = z-pitch
				block.append(CNC.gcode(turn, [("X",x-Radio),("Y",y),("Z", z),("I",Radio), ("J",0)]))

		#Target Level
		if entry == "Center":
			clearanceExit = 0.0	
		clearance = clearanceExit
		alpha= round(Depth / pitch, 4 ) - round(Depth / pitch, 0)
		alpha = alpha * 2*pi 
		Radiox = Radio * cos(alpha)
		Radioy = Radio * sin(alpha)
		xsi = Radiox - clearance* cos(alpha)
		ysi =Radioy - clearance* sin(alpha)
		xse = Radiox + clearance* cos(alpha)
		yse =Radioy + clearance* sin(alpha)
		z = Depth



		if helicalCut == "Helical Cut":
			block.append(CNC.gcode(turn, [("X",x-Radio),("Y",y),("Z", z),("I",Radio), ("J",0)]))
			#Last flat pass
			block.append(CNC.gcode(turn, [("X",x-Radio),("Y",y),("Z", z),("I",Radio), ("J",0)]))
		elif helicalCut == 	"Internal Right Thread" or helicalCut == "External Right Thread":
			block.append(CNC.gcode(turn, [("X",x-Radiox),("Y",y-Radioy),("Z", z),("I",Radio), ("J",0)]))

		elif helicalCut == 	"Internal Left Thread" or helicalCut ==	"External Left Thread":
			block.append(CNC.gcode(turn, [("X",x-Radiox),("Y",y+Radioy),("Z", z),("I",Radio), ("J",0)]))

		# Exit clearance 
		if helicalCut == "Internal Right Thread":
			block.append(CNC.gline(x-xsi,y-ysi))
		elif helicalCut == "Internal Left Thread":
			block.append(CNC.gline(x-xsi,y+ysi))
		if helicalCut == "External Right Thread":
			block.append(CNC.gline(x-xse,y-yse))
		elif helicalCut == "External Left Thread":
			block.append(CNC.gline(x-xse,y+yse))

		# Return to Z Safe
		if returnToSafeZ == 1: 
			if helicalCut == "Helical Cut" or helicalCut == "Internal Right Thread" or helicalCut == "Internal Left Thread":
				if entry == "Center":
					block.append(CNC.gline(x,y))
			block.append(CNC.zsafe())

		blocks.append(block)
		active = app.activeBlock()
		app.gcode.insBlocks(active, blocks, "Helical_Descent inserted")	#<<< insert blocks over active block in the editor
		app.refresh()												#<<< refresh editor
		app.setStatus(_("Generated: Helical_Descent Result"))				#<<< feed back result