Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to TweakAtZ 4.0.4 #1475

Open
wants to merge 1 commit into
base: SteamEngine
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 29 additions & 35 deletions plugins/TweakAtZ.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Name: Tweak At Z 4.0.1
#Name: Tweak At Z 4.0.4
#Info: Change printing parameters at a given height
#Help: TweakAtZ
#Depend: GCode
Expand Down Expand Up @@ -43,8 +43,10 @@
## extruder three code removed, tweaking print speed, save call of Publisher class,
## uses previous value from other plugins also on UltiGCode
##V4.0.1: Bugfix for doubled G1 commands

version = '4.0.1'
##V4.0.2: uses Cura progress bar instead of its own
##V4.0.3: added coolheadlift support, also added support for tweaks at first (0) layer
##V4.0.4: Bugfix for fall back after one layer and doubled G0 commands when using print speed tweak
version = '4.0.4'

import re
import wx
Expand Down Expand Up @@ -128,22 +130,18 @@ def getValue(line, key, default = None):
except:
targetL_i = -100000

if Publisher is not None:
if targetL_i > -100000:
wx.CallAfter(Publisher().sendMessage, "pluginupdate",
"OpenPluginProgressWindow;TweakAtZ;Tweak At Z plugin is executed at layer " + str(targetL_i))
else:
wx.CallAfter(Publisher().sendMessage, "pluginupdate",
"OpenPluginProgressWindow;TweakAtZ;Tweak At Z plugin is executed at height " + str(targetZ) + "mm")
with open(filename, "w") as file:
for line in lines:
if int(i*100/l) > lastpercentage and Publisher is not None: #progressbar
lastpercentage = int(i*100/l)
wx.CallAfter(Publisher().sendMessage, "pluginupdate", "Progress;" + str(lastpercentage))
if targetL_i > -100000:
wx.CallAfter(Publisher().sendMessage, "pluginupdate", ("TweakAtZ Layer %d" % targetL_i) + ";" + str(lastpercentage))
else:
wx.CallAfter(Publisher().sendMessage, "pluginupdate", ("TweakAtZ %1.2f" % targetZ) + "mm;" + str(lastpercentage))
if ';Layer count:' in line:
TWinstances += 1
file.write(';TweakAtZ instances: %d\n' % TWinstances)
if not ('M84' in line or 'M25' in line or ('G1' in line and TweakPrintSpeed and state==3) or
if not ('M84' in line or 'M25' in line or ('G1' in line and TweakPrintSpeed and (state==3 or state==4)) or
';TweakAtZ instances:' in line):
file.write(line)
IsUM2 = ('FLAVOR:UltiGCode' in line) or IsUM2 #Flavor is UltiGCode!
Expand All @@ -157,13 +155,14 @@ def getValue(line, key, default = None):
TWinstances = tempTWi
if ';Small layer' in line: #checks for begin of Cool Head Lift
old['state'] = state
state = 0
#if ('G4' in line) and old['state'] > -1:
#old['state'] = -1
state = 0
if ';LAYER:' in line: #new layer no. found
if state == 0:
state = old['state']
layer = getValue(line, ';LAYER:', layer)
if targetL_i > -100000: #target selected by layer no.
if state == 2 and layer >= targetL_i: #determine targetZ from layer no.
if (state == 2 or targetL_i == 0) and layer == targetL_i: #determine targetZ from layer no.; checks for tweak on layer 0
state = 2
targetZ = z + 0.001
if (getValue(line, 'T', None) is not None) and (getValue(line, 'M', None) is None): #looking for single T-cmd
pres_ext = getValue(line, 'T', pres_ext)
Expand Down Expand Up @@ -197,13 +196,13 @@ def getValue(line, key, default = None):
y = getValue(line, 'Y', None)
e = getValue(line, 'E', None)
f = getValue(line, 'F', None)
if TweakPrintSpeed and state==3:
if 'G1' in line and TweakPrintSpeed and (state==3 or state==4):
# check for pure print movement in target range:
if 'G1' in line and x != None and y != None and f != None and e != None and newZ==z:
if x != None and y != None and f != None and e != None and newZ==z:
file.write("G1 F%d X%1.3f Y%1.3f E%1.5f\n" % (int(f/100.0*float(printspeed)),getValue(line,'X'),
getValue(line,'Y'),getValue(line,'E')))
else: #G1 command but not a print movement
file.write(line)
else: #G1 command but not a print movement
file.write(line)
# no tweaking on retraction hops which have no x and y coordinate:
if (newZ != z) and (x is not None) and (y is not None):
z = newZ
Expand Down Expand Up @@ -244,29 +243,24 @@ def getValue(line, key, default = None):
file.write(";TweakAtZ V%s: reset on Layer %d\n" % (version,layer))
else:
file.write(";TweakAtZ V%s: reset at %1.2f mm\n" % (version,z))
if not oldValueUnknown:
if not IsUM2:#executes only for UM Original and UM2 with RepRap flavor
for key in TweakProp:
if TweakProp[key]:
file.write(TweakStrings[key] % float(old[key]))
else: #executes on UM2 with Ultigcode
file.write("M606 S%d;recalls saved settings\n" % (TWinstances-1))
if IsUM2 and oldValueUnknown: #executes on UM2 with Ultigcode and machine setting
file.write("M606 S%d;recalls saved settings\n" % (TWinstances-1))
else: #executes on RepRap, UM2 with Ultigcode and Cura setting
for key in TweakProp:
if TweakProp[key]:
file.write(TweakStrings[key] % float(old[key]))
# re-activates the plugin if executed by pre-print G-command, resets settings:
if z < targetZ and state >= 3:
if (z < targetZ or layer == 0) and state >= 3: #resets if below tweak level or at level 0
state = 2
done_layers = 0
if targetL_i > -100000:
file.write(";TweakAtZ V%s: reset below Layer %d\n" % (version,targetL_i))
else:
file.write(";TweakAtZ V%s: reset below %1.2f mm\n" % (version,targetZ))
if not IsUM2: #executes only for UM Original and UM2 with RepRap flavor
if IsUM2 and oldValueUnknown: #executes on UM2 with Ultigcode and machine setting
file.write("M606 S%d;recalls saved settings\n" % (TWinstances-1))
else: #executes on RepRap, UM2 with Ultigcode and Cura setting
for key in TweakProp:
if TweakProp[key]:
file.write(TweakStrings[key] % float(old[key]))
else:
file.write("M606 ;recalls saved settings\n")
i+=1
if Publisher is not None:
wx.CallAfter(Publisher().sendMessage, "pluginupdate", "Progress;100")
time.sleep(1)
wx.CallAfter(Publisher().sendMessage, "pluginupdate", "ClosePluginProgressWindow")