注释
这是你的 g 代码生成器的一个功能,使用 Fusion360,有很多!!!!像这样的功能 |
@Fosforitoferch 我使用 bCNC 作为我的 g 代码生成器,所以我希望我能在 bCNC 中看到这个功能。Fusion360 不适用于 Linux。另外我想这太过时了。 |
在我看来,相关代码位于
|
我想所需要的只是计算要切割的路径的总长度(可能使用 例如。: 我们将降压 (DOC) 设置为 20mm。 计算弧的长度可能有点棘手,但也不应该太难。 |
我不是真正的 python 专家,我也不太了解 bCNC 的内部工作原理,但我尝试修改这两个函数并获得了一些结果。这是螺旋切割矩形的图像。我刚刚从 DXF 中选择了矩形并单击了 bCNC 中的 CUT 按钮: 这是我修改后的代码 来自路径() #----------------------------------------------------------------------
# create a block from Path
#----------------------------------------------------------------------
def fromPath(self, path, block=None, z=None, entry=True, exit=True, zinit=0):
if block is None:
if isinstance(path, Path):
block = Block(path.name)
else:
block = Block(path[0].name)
def addSegment(segment, z=None):
x,y = segment.B
if segment.type == Segment.LINE:
x,y = segment.B
#block.append("g1 %s %s"%(self.fmt("x",x,7),self.fmt("y",y,7)))
if z is None: block.append("g1 %s %s"%(self.fmt("x",x,7),self.fmt("y",y,7)))
else: block.append("g1 %s %s %s"%(self.fmt("x",x,7),self.fmt("y",y,7),self.fmt("z",z,7)))
elif segment.type in (Segment.CW, Segment.CCW):
ij = segment.C - segment.A
if abs(ij[0])<1e-5: ij[0] = 0.
if abs(ij[1])<1e-5: ij[1] = 0.
block.append("g%d %s %s %s %s" % \
(segment.type,
self.fmt("x",x,7), self.fmt("y",y,7),
self.fmt("i",ij[0],7),self.fmt("j",ij[1],7)))
if isinstance(path, Path):
x,y = path[0].A
if z is None: z = self.cnc["surface"]
if entry:
block.append("g0 %s %s"%(self.fmt("x",x,7),self.fmt("y",y,7)))
#zinit = 0;
block.append(CNC.zenter(zinit))
setfeed = True
prevInside = None
#print(path.length())
print("");
for segment in path:
#print(segment.length())
#print(100*segment.length()/path.length())
if zinit is not None:
zinit = zinit + (segment.length()/path.length())*z
print(zinit)
if prevInside is not segment._inside:
if segment._inside is None:
block.append(CNC.zenter(z))
setfeed = True
elif segment._inside.z > z:
block.append(CNC.zexit(segment._inside.z))
setfeed = True
prevInside = segment._inside
addSegment(segment, zinit)
# x,y = segment.B
# if segment.type == Segment.LINE:
# x,y = segment.B
# block.append("g1 %s %s"%(self.fmt("x",x,7),self.fmt("y",y,7)))
# elif segment.type in (Segment.CW, Segment.CCW):
# ij = segment.C - segment.A
# if abs(ij[0])<1e-5: ij[0] = 0.
# if abs(ij[1])<1e-5: ij[1] = 0.
# block.append("g%d %s %s %s %s" % \
# (segment.type,
# self.fmt("x",x,7), self.fmt("y",y,7),
# self.fmt("i",ij[0],7),self.fmt("j",ij[1],7)))
if setfeed:
block[-1] += " %s"%(self.fmt("f",self.cnc["cutfeed"]))
setfeed = False
if exit:
block.append(CNC.zsafe())
else:
for p in path:
self.fromPath(p, block)
return block
切割路径() #----------------------------------------------------------------------
# Perform a cut on a path an add it to block
# @param newblock O block to add the cut paths
# @param block I existing block
# @param path I path to cut
# @param z I starting z surface
# @param depth I ending depth
# @param stepz I stepping in z
#----------------------------------------------------------------------
def cutPath(self, newblock, block, path, z, depth, stepz):
closed = path.isClosed()
entry = True
exit = False
# Mark in which tab we are inside
if block.tabs:
# Mark everything as outside
for tab in block.tabs:
tab.create(CNC.vars["diameter"])
tab.split(path)
zinit = 0
while z > depth:
z = max(z-stepz, depth)
if not closed:
# on open paths always enter exit
entry = exit = True
elif abs(z-depth)<1e-7:
# last pass
exit = True
self.fromPath(path, newblock, z, entry, exit, zinit)
zinit = z
entry = False
return newblock
我仍然遗漏了一些东西,生成的 g 代码存在重大问题。你能帮我改进这段代码以使其可用吗? 最大的问题是某些东西在通过之间将 Z 提升了一点,导致无意义的刀具路径。侧面图: 当我手动删除这些 Z 移动时,它开始有意义: 我不太确定这对非线段的效果如何。(例如圆弧和圆)。但我很确定有些东西会坏掉。 问题是我真的不知道g代码。现在我用这个: 设置线段的最终 Z 高度,适用于线条。但是 |
当我手动添加 任何想法如何在将任何段添加到块之前可靠地添加/修改 Z ? |
啊哈!终于让它工作了! 还添加了最后一个平面通行证: 这是一些代码: 来自路径() #----------------------------------------------------------------------
# create a block from Path
#----------------------------------------------------------------------
def fromPath(self, path, block=None, z=None, entry=True, exit=True, stepz=0):
if block is None:
if isinstance(path, Path):
block = Block(path.name)
else:
block = Block(path[0].name)
def addSegment(segment, z=None):
x,y = segment.B
if segment.type == Segment.LINE:
x,y = segment.B
#block.append("g1 %s %s"%(self.fmt("x",x,7),self.fmt("y",y,7)))
if z is None: block.append("g1 %s %s"%(self.fmt("x",x,7),self.fmt("y",y,7)))
else: block.append("g1 %s %s %s"%(self.fmt("x",x,7),self.fmt("y",y,7),self.fmt("z",z,7)))
elif segment.type in (Segment.CW, Segment.CCW):
ij = segment.C - segment.A
if abs(ij[0])<1e-5: ij[0] = 0.
if abs(ij[1])<1e-5: ij[1] = 0.
if z is None:
block.append("g%d %s %s %s %s" % \
(segment.type,
self.fmt("x",x,7), self.fmt("y",y,7),
self.fmt("i",ij[0],7),self.fmt("j",ij[1],7)))
else:
block.append("g%d %s %s %s %s %s" % \
(segment.type,
self.fmt("x",x,7), self.fmt("y",y,7),
self.fmt("i",ij[0],7),self.fmt("j",ij[1],7),self.fmt("z",z,7)))
if isinstance(path, Path):
x,y = path[0].A
if z is None: z = self.cnc["surface"]
if entry:
block.append("g0 %s %s"%(self.fmt("x",x,7),self.fmt("y",y,7)))
#zinit = 0;
#block.append(CNC.zenter(zinit))
setfeed = True
prevInside = None
#print(path.length())
print("");
zh = z + stepz;
for segment in path:
#print(segment.length())
#print(100*segment.length()/path.length())
zh -= (segment.length()/path.length())*stepz
print(zh)
if prevInside is not segment._inside:
if segment._inside is None:
block.append(CNC.zenter(z))
setfeed = True
elif segment._inside.z > z:
block.append(CNC.zexit(segment._inside.z))
setfeed = True
prevInside = segment._inside
addSegment(segment, zh)
# x,y = segment.B
# if segment.type == Segment.LINE:
# x,y = segment.B
# block.append("g1 %s %s"%(self.fmt("x",x,7),self.fmt("y",y,7)))
# elif segment.type in (Segment.CW, Segment.CCW):
# ij = segment.C - segment.A
# if abs(ij[0])<1e-5: ij[0] = 0.
# if abs(ij[1])<1e-5: ij[1] = 0.
# block.append("g%d %s %s %s %s" % \
# (segment.type,
# self.fmt("x",x,7), self.fmt("y",y,7),
# self.fmt("i",ij[0],7),self.fmt("j",ij[1],7)))
if setfeed:
block[-1] += " %s"%(self.fmt("f",self.cnc["cutfeed"]))
setfeed = False
if exit:
block.append(CNC.zsafe())
else:
for p in path:
self.fromPath(p, block)
return block
切割路径() #----------------------------------------------------------------------
# Perform a cut on a path an add it to block
# @param newblock O block to add the cut paths
# @param block I existing block
# @param path I path to cut
# @param z I starting z surface
# @param depth I ending depth
# @param stepz I stepping in z
#----------------------------------------------------------------------
def cutPath(self, newblock, block, path, z, depth, stepz):
closed = path.isClosed()
entry = True
exit = False
# Mark in which tab we are inside
if block.tabs:
# Mark everything as outside
for tab in block.tabs:
tab.create(CNC.vars["diameter"])
tab.split(path)
#zinit = 0
while z > depth:
z = max(z-stepz, depth)
if not closed:
# on open paths always enter exit
entry = exit = True
elif abs(z-depth)<1e-7:
# last pass
exit = False
self.fromPath(path, newblock, z, entry, exit, stepz)
#zinit = z
entry = False
self.fromPath(path, newblock, z, entry, exit, 0)
return newblock
|
现在最大的问题是它破坏了原始的 CUT 功能。我需要修改代码,这样我们就可以在螺旋切割和非螺旋切割之间切换…… |
出来了!:-) |
只是添加了正确的进入和退出路径以避免崩溃。 |
标签现在可以在螺旋切割中使用! 我也有坡道切割工作!它就像螺旋线,但下降速度更快,然后像往常一样继续切割平整(以防止在第一次通过时摩擦): 一切准备就绪#893 这孩子会撕裂一些铝!:-) |
我想现在已经实现了 |
在很多情况下,最好是在 X/Y 轴上切入时向下切入,这样可以防止铣削直接向下。对于某些工具,它甚至是唯一的选择…您能否将其添加为 CUT 操作的选项?
例如。当你切割圆圈时。你不会在 Z 中向下然后做 XY 圆然后再次在 Z 中向下。相反,您可以将最后一层作为唯一平坦的一层进行螺旋切割。