diff options
author | daid <daid303@gmail.com> | 2014-02-12 15:58:18 +0400 |
---|---|---|
committer | daid <daid303@gmail.com> | 2014-02-12 15:58:18 +0400 |
commit | c9ba5d1049a427e295ebc5ec4239efae75bd0bd4 (patch) | |
tree | ce3625acd61ae0c74c54e56ca9357fb0f1405bd8 /plugins | |
parent | fed38bc86d17f266f3cf318f6df753a475e7a648 (diff) |
Move resources and plugins out of the Cura python package.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/TweakAtZ.py | 153 | ||||
-rw-r--r-- | plugins/pauseAtZ.py | 70 |
2 files changed, 223 insertions, 0 deletions
diff --git a/plugins/TweakAtZ.py b/plugins/TweakAtZ.py new file mode 100644 index 0000000000..d71e70a713 --- /dev/null +++ b/plugins/TweakAtZ.py @@ -0,0 +1,153 @@ +#Name: Tweak At Z 3.1 +#Info: Change printing parameters at a given height +#Help: TweakAtZ +#Depend: GCode +#Type: postprocess +#Param: targetZ(float:5.0) Z height to tweak at (mm) +#Param: targetL(int:) (ALT) Layer no. to tweak at +#Param: speed(int:) New Speed (%) +#Param: flowrate(int:) New Flow Rate (%) +#Param: platformTemp(int:) New Bed Temp (deg C) +#Param: extruderOne(int:) New Extruder 1 Temp (deg C) +#Param: extruderTwo(int:) New Extruder 2 Temp (deg C) +#Ex3 #Param: extruderThree(int:) New Extruder 3 Temp (deg C) +#Param: fanSpeed(int:) New Fan Speed (0-255 PWM) + +## Written by Steven Morlock, smorloc@gmail.com +## Modified by Ricardo Gomez, ricardoga@otulook.com, to add Bed Temperature and make it work with Cura_13.06.04+ +## Modified by Stefan Heule, Dim3nsioneer@gmx.ch, to add Flow Rate, restoration of initial values when returning to low Z, extended stage numbers, direct stage manipulation by GCODE-comments, UltiGCode regocnition, addition of fan speed, alternative selection by layer no., disabling extruder three +## This script is licensed under the Creative Commons - Attribution - Share Alike (CC BY-SA) terms + +# Uses - +# M220 S<factor in percent> - set speed factor override percentage +# M221 S<factor in percent> - set flow factor override percentage +# M104 S<temp> T<0-#toolheads> - set extruder <T> to target temperature <S> +# M140 S<temp> - set bed target temperature +# M106 S<PWM> - set fan speed to target speed <S> + +#history / changelog: +#V3.0.1: TweakAtZ-state default 1 (i.e. the plugin works without any TweakAtZ comment) +#V3.1: Recognizes UltiGCode and deactivates value reset, fan speed added, alternatively layer no. to tweak at, extruder three temperature disabled by '#Ex3' + +version = '3.1' + +import re + +def getValue(line, key, default = None): + if not key in line or (';' in line and line.find(key) > line.find(';') and not ";TweakAtZ" in key and not ";LAYER:" in key): + return default + subPart = line[line.find(key) + len(key):] #allows for string lengths larger than 1 + if ";TweakAtZ" in key: + m = re.search('^[0-3]', subPart) + elif ";LAYER:" in key: + m = re.search('^[+-]?[0-9]*', subPart) + else: + m = re.search('^[0-9]+\.?[0-9]*', subPart) + if m == None: + return default + try: + return float(m.group(0)) + except: + return default + +with open(filename, "r") as f: + lines = f.readlines() + +old_speed = 100 +old_flowrate = 100 +old_platformTemp = -1 +old_extruderOne = -1 +old_extruderTwo = -1 +#Ex3 old_extruderThree = -1 +old_fanSpeed = 0 +pres_ext = 0 +z = 0 +x = 0 +y = 0 +layer = -100000 #layer no. may be negative (raft) but never that low +state = 1 #state 0: deactivated, state 1: activated, state 2: active, but below z, state 3: active, passed z +no_reset = 0 #Default setting is reset (ok for Marlin/Sprinter), has to be set to 1 for UltiGCode (work-around for missing default values) + +try: + targetL_i = int(targetL) + targetZ = 100000 +except: + targetL_i = -100000 + +with open(filename, "w") as f: + for line in lines: + f.write(line) + if 'FLAVOR:UltiGCode' in line: #Flavor is UltiGCode! No reset of values + no_reset = 1 + if ';TweakAtZ-state' in line: #checks for state change comment + state = getValue(line, ';TweakAtZ-state', state) + if ';LAYER:' in line: #new layer no. found + 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. + targetZ = z + 0.001 + if (getValue(line, 'T', None) is not None) and (getValue(line, 'M', None) is None): #looking for single T-command + pres_ext = getValue(line, 'T', pres_ext) + if 'M190' in line or 'M140' in line and state < 3: #looking for bed temp, stops after target z is passed + old_platformTemp = getValue(line, 'S', old_platformTemp) + if 'M109' in line or 'M104' in line and state < 3: #looking for extruder temp, stops after target z is passed + if getValue(line, 'T', pres_ext) == 0: + old_extruderOne = getValue(line, 'S', old_extruderOne) + elif getValue(line, 'T', pres_ext) == 1: + old_extruderTwo = getValue(line, 'S', old_extruderTwo) +#Ex3 elif getValue(line, 'T', pres_ext) == 2: +#Ex3 old_extruderThree = getValue(line, 'S', old_extruderThree) + if 'M107' in line: #fan is stopped; is always updated in order not to miss switch off for next object + old_fanSpeed = 0 + if 'M106' in line and state < 3: #looking for fan speed + old_fanSpeed = getValue(line, 'S', old_fanSpeed) + if 'G1' in line or 'G0' in line: + newZ = getValue(line, 'Z', z) + x = getValue(line, 'X', x) + y = getValue(line, 'Y', y) + if newZ != z: + z = newZ + if z < targetZ and state == 1: + state = 2 + if z >= targetZ and state == 2: + state = 3 + if targetL_i > -100000: + f.write(";TweakAtZ V%s: executed at Layer %d\n" % (version,targetL_i)) + else: + f.write(";TweakAtZ V%s: executed at %1.2f mm\n" % (version,targetZ)) + if speed is not None and speed != '': + f.write("M220 S%f\n" % float(speed)) + if flowrate is not None and flowrate != '': + f.write("M221 S%f\n" % float(flowrate)) + if platformTemp is not None and platformTemp != '': + f.write("M140 S%f\n" % float(platformTemp)) + if extruderOne is not None and extruderOne != '': + f.write("M104 S%f T0\n" % float(extruderOne)) + if extruderTwo is not None and extruderTwo != '': + f.write("M104 S%f T1\n" % float(extruderTwo)) +#Ex3 if extruderThree is not None and extruderThree != '': +#Ex3 f.write("M104 S%f T2\n" % float(extruderThree)) + if fanSpeed is not None and fanSpeed != '': + f.write("M106 S%d\n" % int(fanSpeed)) + if z < targetZ and state == 3: #re-activates the plugin if executed by pre-print G-command, resets settings + state = 2 + if no_reset == 0: #executes only for UM Original and UM2 with RepRap flavor + if targetL_i > -100000: + f.write(";TweakAtZ V%s: reset below Layer %d\n" % (version,targetL_i)) + else: + f.write(";TweakAtZ V%s: reset below %1.2f mm\n" % (version,targetZ)) + if speed is not None and speed != '': + f.write("M220 S%f\n" % float(old_speed)) + if flowrate is not None and flowrate != '': + f.write("M221 S%f\n" % float(old_flowrate)) + if platformTemp is not None and platformTemp != '': + f.write("M140 S%f\n" % float(old_platformTemp)) + if extruderOne is not None and extruderOne != '': + f.write("M104 S%f T0\n" % float(old_extruderOne)) + if extruderTwo is not None and extruderTwo != '': + f.write("M104 S%f T1\n" % float(old_extruderTwo)) +#Ex3 if extruderThree is not None and extruderThree != '': +#Ex3 f.write("M104 S%f T2\n" % float(old_extruderThree)) + if fanSpeed is not None and fanSpeed != '': + f.write("M106 S%d;\n" % int(old_fanSpeed)) + diff --git a/plugins/pauseAtZ.py b/plugins/pauseAtZ.py new file mode 100644 index 0000000000..d0f733e8d6 --- /dev/null +++ b/plugins/pauseAtZ.py @@ -0,0 +1,70 @@ +#Name: Pause at height +#Info: Pause the printer at a certain height +#Depend: GCode +#Type: postprocess +#Param: pauseLevel(float:5.0) Pause height (mm) +#Param: parkX(float:190) Head park X (mm) +#Param: parkY(float:190) Head park Y (mm) +#Param: retractAmount(float:5) Retraction amount (mm) + +__copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License" +import re + +def getValue(line, key, default = None): + if not key in line or (';' in line and line.find(key) > line.find(';')): + return default + subPart = line[line.find(key) + 1:] + m = re.search('^[0-9]+\.?[0-9]*', subPart) + if m is None: + return default + try: + return float(m.group(0)) + except: + return default + +with open(filename, "r") as f: + lines = f.readlines() + +z = 0. +x = 0. +y = 0. +pauseState = 0 +currentSectionType = 'STARTOFFILE' +with open(filename, "w") as f: + for line in lines: + if line.startswith(';'): + if line.startswith(';TYPE:'): + currentSectionType = line[6:].strip() + f.write(line) + continue + if getValue(line, 'G', None) == 1 or getValue(line, 'G', None) == 0: + newZ = getValue(line, 'Z', z) + x = getValue(line, 'X', x) + y = getValue(line, 'Y', y) + if newZ != z and currentSectionType != 'CUSTOM': + z = newZ + if z < pauseLevel and pauseState == 0: + pauseState = 1 + if z >= pauseLevel and pauseState == 1: + pauseState = 2 + f.write(";TYPE:CUSTOM\n") + #Retract + f.write("M83\n") + f.write("G1 E-%f F6000\n" % (retractAmount)) + #Move the head away + f.write("G1 X%f Y%f F9000\n" % (parkX, parkY)) + if z < 15: + f.write("G1 Z15 F300\n") + #Wait till the user continues printing + f.write("M0\n") + #Push the filament back, and retract again, the properly primes the nozzle when changing filament. + f.write("G1 E%f F6000\n" % (retractAmount)) + f.write("G1 E-%f F6000\n" % (retractAmount)) + #Move the head back + if z < 15: + f.write("G1 Z%f F300\n" % (z+1)) + f.write("G1 X%f Y%f F9000\n" % (x, y)) + f.write("G1 E%f F6000\n" % (retractAmount)) + f.write("G1 F9000\n") + f.write("M82\n") + f.write(line) |