我写了一个小型的python Gcode后处理器,为3D打印添加了一些内容。最初的问题是,每次更换工具头时,我都需要3D打印机生成清除块。如果没有更换该层的工具,则仍需要建立吹扫模块,并在层的末尾使用活动的任何工具来结束该层的末端(因此,塔筒继续增加高度而不会丢失层)。
很抱歉,这很难想象,我添加了一些照片,以减少想象力:
在处理器运行之前:https://i.imgur.com/nr1daQp.png
运行处理器后:https://i.imgur.com/uGxWogc.png
问题区域https://i.imgur.com/eRaxopd.png
问题在于,当仅打印一种颜色时,似乎只能建立一塔。这可以通过缺少一层来看出,然后一个塔比另一个塔短,因为最后50层都是蓝色。谁能阐明为什么会这样?
更新:我注意到代码在说,尽管修改后的Gcode中没有左右两层,但它已将左右两层的塔放下了。这意味着它必须使用rightwriter函数放下右塔,然后使用leftwriter函数覆盖它。我不明白为什么会这样,我在调用写函数之间调用了nextzvalue函数来避免这种情况。我的解决方法是让它打印出包含两个带有独立功能的塔式Gcode的代码,但id想知道为什么会这样。
代码:
def main():
file = open("example.gcode","r")
lines = file.readlines()
file.close
oldzline = 320
tower1count = 0
tower2count = 0
layercount = 0
linecounter = 0
numberoflayers = layercounter(lines)
toollist=[]
while layercount < numberoflayers:
tower1count=0
tower2count=0
nextzline = nextzvalue(lines,oldzline)
print("layer count: ",layercount)
for line in lines:
linecounter +=1
if linecounter > oldzline and linecounter < nextzline:
if line.find("TOOL CHANGE") != -1:
if lines[linecounter+3].find("LAYER CHANGE") == -1:
if tower1count==0:
tower1count+=1
print("tower1 count 1: ",tower1count)
rightwriter(linecounter,lines)
elif tower1count==1:
tower2count+=1
print("tower2 count 1: ",tower2count)
if tower2count!= 2:
leftwriter(linecounter,lines)
if tower1count == 0 and tower2count == 0:
nextzline = nextzvalue(lines,oldzline)
tower2count+=1
tower1count+=1
print("tower1 count 2: ",tower1count)
print("tower2 count 2: ",tower2count)
rightwriter(nextzline-4,lines) <<<<<<right writer code being overwritten.
nextzline = nextzvalue(lines,oldzline)<<<<< I believe this bit is not working correctly.
leftwriter(nextzline-4,lines) <<<< causing this to overwrite the code added by the rightwriter function.
elif tower1count == 0:
nextzline = nextzvalue(lines,oldzline)
tower1count+=1
print("tower1 count 3: ",tower1count)
rightwriter(nextzline-4,lines)
elif tower2count == 0:
nextzline = nextzvalue(lines,oldzline)
tower2count+=1
print("tower2 count 3: ",tower2count)
leftwriter(nextzline-4,lines)
print("tower 1: ",tower1count)
print("tower 2: ",tower2count)
#if layercount == 121:
#print("sleepy time")
#time.sleep(100)
oldzline = nextzline
linecounter = 0
layercount+=1
def nextzvalue(lines,oldzvalue): # finds the nex Z value i.e. the end of the current layer/beggining of next.
linecount = 0
for line in lines:
linecount+=1
if linecount > oldzvalue:
if line.find("G1") != -1:
if line.find("Z") !=-1:
return(linecount)
def layercounter(lines): #counts the number of layers and returns them as a number
linecount=0
layercount=0
for line in lines:
linecount+=1
if line.find("G1") !=-1and line.find("Z") != -1:
layercount+=1
return(layercount)
def leftwriter(linecount,lines):
linecount = linecount+1
#print("making a T1 layer")
lines[linecount] = "some gcode to draw a layer of left tower here"
with open('Example.gcode','w') as file:
file.writelines(lines)
def rightwriter(linecount,lines):
linecount = linecount+1
#print("making a T2 layer")
lines[linecount] ="some gcode to draw a layer of right tower here"
with open('Example.gcode','w') as file:
file.writelines(lines)
对这篇文章的长度表示歉意。