本文整理汇总了Python中CNC.Block.enable方法的典型用法代码示例。如果您正苦于以下问题:Python Block.enable方法的具体用法?Python Block.enable怎么用?Python Block.enable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CNC.Block
的用法示例。
在下文中一共展示了Block.enable方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make
# 需要导入模块: from CNC import Block [as 别名]
# 或者: from CNC.Block import enable [as 别名]
def make(self,app, XStart=0.0, YStart=0.0, FlatWidth=10., FlatHeight=10., \
FlatDepth=0, BorderPass=False, CutDirection="Climb", PocketType="Raster"):
#GCode Blocks
blocks = []
#Check parameters
if CutDirection is "":
app.setStatus(_("Flatten abort: Cut Direction is undefined"))
return
if PocketType is "":
app.setStatus(_("Flatten abort: Pocket Type is undefined"))
return
if FlatWidth <= 0 or FlatHeight <= 0 :
app.setStatus(_("Flatten abort: Flatten Area dimensions must be > 0"))
return
if FlatDepth > 0 :
app.setStatus(_("Flatten abort: Hey this is only for subtractive machine! Check depth!"))
return
#Add Region disabled to show worked area
block = Block(self.name + " Outline")
block.enable = False
block.append(CNC.zsafe())
xR,yR = self.RectPath(XStart,YStart,FlatWidth,FlatHeight)
for x,y in zip(xR,yR):
block.append(CNC.gline(x,y))
blocks.append(block)
# Load tool and material settings
toolDiam = CNC.vars['diameter']
toolRadius = toolDiam / 2.
#Calc tool diameter with Maximum Step Over allowed
StepOverInUnitMax = toolDiam * CNC.vars['stepover'] / 100.0
#Offset for Border Cut
BorderXStart = XStart + toolRadius
BorderYStart = YStart + toolRadius
BorderWidth = FlatWidth - toolDiam
BorderHeight = FlatHeight - toolDiam
BorderXEnd = XStart + FlatWidth - toolRadius
BorderYEnd = YStart + FlatHeight - toolRadius
PocketXStart = BorderXStart
PocketYStart = BorderYStart
PocketXEnd = BorderXEnd
PocketYEnd = BorderYEnd
#Calc space to work with/without border cut
WToWork = FlatWidth - toolDiam
HToWork = FlatHeight - toolDiam
if(WToWork < toolRadius or HToWork < toolRadius):
app.setStatus(_("Flatten abort: Flatten area is too small for this End Mill."))
return
#Prepare points for pocketing
xP=[]
yP=[]
#and border
xB=[]
yB=[]
#---------------------------------------------------------------------
#Raster approach
if PocketType == "Raster":
#Correct sizes if border is used
if(BorderPass):
PocketXStart += StepOverInUnitMax
PocketYStart += StepOverInUnitMax
PocketXEnd -= StepOverInUnitMax
PocketYEnd -= StepOverInUnitMax
WToWork -= (StepOverInUnitMax)
HToWork -= (StepOverInUnitMax)
#Calc number of pass
VerticalCount = (int)(HToWork / StepOverInUnitMax)
#Calc step minor of Max step
StepOverInUnit = HToWork / (VerticalCount +1)
flip = False
ActualY = PocketYStart
#Zig zag
if StepOverInUnit==0 : StepOverInUnit=0.001 #avoid infinite while loop
while (True):
#Zig
xP.append(self.ZigZag(flip,PocketXStart,PocketXEnd))
yP.append(ActualY)
flip = not flip
#Zag
xP.append(self.ZigZag(flip,PocketXStart,PocketXEnd))
yP.append(ActualY)
if(ActualY >= PocketYEnd - StepOverInUnitMax + StepOverInUnit):
break
#Up
ActualY += StepOverInUnit
xP.append(self.ZigZag(flip,PocketXStart,PocketXEnd))
#.........这里部分代码省略.........
示例2: execute
# 需要导入模块: from CNC import Block [as 别名]
# 或者: from CNC.Block import enable [as 别名]
#.........这里部分代码省略.........
fileName = self["File"]
try:
img = Image.open(fileName)
except:
app.setStatus(_("Halftone abort: Can't read image file"))
return
#Create a scaled image to work faster with big image and better with small ones
squareNorm = True
if channel == 'Blue(sqrt)':
img = img.convert('RGB')
img = img.split()[0]
elif channel == 'Green(sqrt)':
img = img.convert('RGB')
img = img.split()[1]
elif channel == 'Red(sqrt)':
img = img.convert('RGB')
img = img.split()[2]
else:
img = img.convert ('L') #to calculate luminance
squareNorm = False
#flip image to ouput correct coordinates
img = img.transpose(Image.FLIP_TOP_BOTTOM)
#Calc divisions for halftone
divisions = drawSize / cellSize
#Get image size
self.imgWidth, self.imgHeight = img.size
if (self.imgWidth > self.imgHeight):
scale = drawSize / float(self.imgWidth)
sample = int(self.imgWidth / divisions)
else:
scale = drawSize / float(self.imgHeight)
sample = int(self.imgHeight / divisions)
self.ratio = scale
#Halftone
circles = self.halftone(img, sample, scale, angle, squareNorm, invert)
#Init blocks
blocks = []
#Border block
if drawBorder:
block = Block("%s-border"%(self.name))
block.append(CNC.zsafe())
block.append(CNC.grapid(0,0))
block.append(CNC.zenter(depth))
block.append(CNC.gcode(1, [("f",CNC.vars["cutfeed"])]))
block.append(CNC.gline(self.imgWidth * self.ratio, 0))
block.append(CNC.gline(self.imgWidth * self.ratio, self.imgHeight*self.ratio))
block.append(CNC.gline(0, self.imgHeight*self.ratio))
block.append(CNC.gline(0,0))
blocks.append(block)
#Draw block
block = Block(self.name)
#Change color
if channel == 'Blue(sqrt)':
block.color = "#0000ff"
elif channel == 'Green(sqrt)':
block.color = "#00ff00"
elif channel == 'Red(sqrt)':
block.color = "#ff0000"
block.append("(Halftone size W=%d x H=%d x D=%d ,Total points:%i)" %
(self.imgWidth * self.ratio, self.imgHeight * self.ratio, depth, len(circles)))
block.append("(Channel = %s)" % channel)
for c in circles:
x,y,r = c
r = min(dMax/2.0,r)
if (r >= dMin/2.):
block.append(CNC.zsafe())
block.append(CNC.grapid(x+r,y))
block.append(CNC.zenter(depth))
block.append(CNC.garc(CW,x+r,y,i=-r,))
block.append(CNC.zsafe())
if conical: block.enable = False
blocks.append(block)
if conical:
blockCon = Block("%s-Conical"%(self.name))
for c in circles:
x,y,r = c
blockCon.append(CNC.zsafe())
blockCon.append(CNC.grapid(x,y))
dv = r / math.tan(math.radians(v_angle/2.))
blockCon.append(CNC.zenter(-dv))
blockCon.append(CNC.zsafe())
blocks.append(blockCon)
#Gcode Zsafe
active = app.activeBlock()
app.gcode.insBlocks(active, blocks, "Halftone")
app.refresh()
app.setStatus(_("Generated Halftone size W=%d x H=%d x D=%d ,Total points:%i" %
(self.imgWidth * self.ratio, self.imgHeight * self.ratio, depth, len(circles))))
示例3: calc
# 需要导入模块: from CNC import Block [as 别名]
# 或者: from CNC.Block import enable [as 别名]
#.........这里部分代码省略.........
a = 1.0 / Pd
# Outside Circle
Ro = R + a
Do = 2.0 * Ro
# Tooth thickness
T = math.pi*D / (2*N)
# undercut?
U = 2.0 / (math.sin(phi) * (math.sin(phi)))
needs_undercut = N < U
# sys.stderr.write("N:%s R:%s Rb:%s\n" % (N,R,Rb))
# Clearance
c = 0.0
# Dedendum
b = a + c
# Root Circle
Rr = R - b
Dr = 2.0*Rr
two_pi = 2.0*math.pi
half_thick_angle = two_pi / (4.0*N)
pitch_to_base_angle = self.involute_intersect_angle(Rb, R)
pitch_to_outer_angle = self.involute_intersect_angle(Rb, Ro) # pitch_to_base_angle
points = []
for x in range(1,N+1):
c = x * two_pi / N
# angles
pitch1 = c - half_thick_angle
base1 = pitch1 - pitch_to_base_angle
outer1 = pitch1 + pitch_to_outer_angle
pitch2 = c + half_thick_angle
base2 = pitch2 + pitch_to_base_angle
outer2 = pitch2 - pitch_to_outer_angle
# points
b1 = self.point_on_circle(Rb, base1)
p1 = self.point_on_circle(R, pitch1)
o1 = self.point_on_circle(Ro, outer1)
o2 = self.point_on_circle(Ro, outer2)
p2 = self.point_on_circle(R, pitch2)
b2 = self.point_on_circle(Rb, base2)
if Rr >= Rb:
pitch_to_root_angle = pitch_to_base_angle - self.involute_intersect_angle(Rb, Rr)
root1 = pitch1 - pitch_to_root_angle
root2 = pitch2 + pitch_to_root_angle
r1 = self.point_on_circle(Rr, root1)
r2 = self.point_on_circle(Rr, root2)
points.append(r1)
points.append(p1)
points.append(o1)
points.append(o2)
points.append(p2)
points.append(r2)
else:
r1 = self.point_on_circle(Rr, base1)
r2 = self.point_on_circle(Rr, base2)
points.append(r1)
points.append(b1)
points.append(p1)
points.append(o1)
points.append(o2)
points.append(p2)
points.append(b2)
points.append(r2)
first = points[0]
del points[0]
blocks = []
block = Block(self.name)
blocks.append(block)
block.append(CNC.grapid(first.x(), first.y()))
block.append(CNC.zenter(0.0))
#print first.x(), first.y()
for v in points:
block.append(CNC.gline(v.x(), v.y()))
#print v.x(), v.y()
#print first.x(), first.y()
block.append(CNC.gline(first.x(), first.y()))
block.append(CNC.zsafe())
#block = Block("%s-center"%(self.name))
block = Block("%s-basecircle"%(self.name))
block.enable = False
block.append(CNC.grapid(Db/2, 0.))
block.append(CNC.zenter(0.0))
block.append(CNC.garc(CW, Db/2, 0., i=-Db/2))
block.append(CNC.zsafe())
blocks.append(block)
return blocks
示例4: execute
# 需要导入模块: from CNC import Block [as 别名]
# 或者: from CNC.Block import enable [as 别名]
def execute(self, app):
try:
from PIL import Image
except:
app.setStatus(_("Sketch abort: This plugin requires PIL/Pillow to read image data"))
return
n = self["name"]
if not n or n=="default": n="Sketch"
#Calc desired size
grundgy =self["Grundgy"]
maxSize = self["MaxSize"]
squiggleTotal = self["SquiggleTotal"]
squiggleLength = self["SquiggleLength"]
depth = self["Depth"]
drawBorder = self["DrawBorder"]
channel = self["Channel"]
radius = 1
if grundgy == "Low":
radius = 2
elif grundgy == "Medium":
radius = 3
elif grundgy == "High":
radius = 6
elif grundgy == "Very High":
radius = 9
#Check parameters
if maxSize < 1:
app.setStatus(_("Sketch abort: Too small to draw anything!"))
return
if squiggleTotal < 1:
app.setStatus(_("Sketch abort: Please let me draw at least 1 squiggle"))
return
if squiggleLength <= 0:
app.setStatus(_("Sketch abort: Squiggle Length must be > 0"))
return
fileName = self["File"]
try:
img = Image.open(fileName)
except:
app.setStatus(_("Sketch abort: Can't read image file"))
return
#Create a scaled image to work faster with big image and better with small ones
iWidth,iHeight = img.size
resampleRatio = 800.0 / iHeight
img = img.resize((int(iWidth *resampleRatio) ,int(iHeight * resampleRatio)), Image.ANTIALIAS)
if channel == 'Blue':
img = img.convert('RGB')
img = img.split()[0]
elif channel == 'Green':
img = img.convert('RGB')
img = img.split()[1]
elif channel == 'Red':
img = img.convert('RGB')
img = img.split()[2]
else:
img = img.convert ('L') #to calculate luminance
img = img.transpose(Image.FLIP_TOP_BOTTOM) #ouput correct image
pix = img.load()
#Get image size
self.imgWidth, self.imgHeight = img.size
self.ratio = 1
if (iWidth > iHeight):
self.ratio = maxSize / float(self.imgWidth)
else:
self.ratio = maxSize / float(self.imgHeight)
#Init blocks
blocks = []
#Border block
block = Block("%s-border"%(self.name))
block.enable = drawBorder
block.append(CNC.zsafe())
block.append(CNC.grapid(0,0))
block.append(CNC.zenter(depth))
block.append(CNC.gcode(1, [("f",CNC.vars["cutfeed"])]))
block.append(CNC.gline(self.imgWidth * self.ratio, 0))
block.append(CNC.gline(self.imgWidth * self.ratio, self.imgHeight*self.ratio))
block.append(CNC.gline(0, self.imgHeight*self.ratio))
block.append(CNC.gline(0,0))
blocks.append(block)
#Draw block
block = Block(self.name)
block.append("(Sketch size W=%d x H=%d x distance=%d)" %
(self.imgWidth * self.ratio , self.imgHeight * self.ratio , depth))
block.append("(Channel = %s)" %(channel))
#choose a nice starting point
x = self.imgWidth / 4.
y = self.imgHeight / 4.
#.........这里部分代码省略.........