Skip to content

Instantly share code, notes, and snippets.

@FlyingSuricate
Last active January 2, 2021 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FlyingSuricate/e60faddb476564a8d787cc60bffa1fdc to your computer and use it in GitHub Desktop.
Save FlyingSuricate/e60faddb476564a8d787cc60bffa1fdc to your computer and use it in GitHub Desktop.
Ultimaker Cura script for CustomeTimelapse modified for an Ultimaker 3
from ..Script import Script
class CustomTimelapse(Script):
def __init__(self):
super().__init__()
def getSettingDataString(self):
return """{
"name": "Custom timelapse",
"key": "CustomTimelapse",
"metadata": {},
"version": 2,
"settings":
{
"activate_plugin":
{
"label": "Enable plugin",
"description": "Select if you want the plugin to be active (allows you to desactivate without losing your configuration)",
"type": "bool",
"default_value": true
},
"first_gcode":
{
"label": "GCODE for the first position(display position).",
"description": "GCODE to add before or after layer change.",
"type": "str",
"default_value": "G0 X190 Y215 F7000"
},
"second_gcode":
{
"label": "GCODE for the second position(trigger position).",
"description": "GCODE to add before or after layer change.",
"type": "str",
"default_value": "G0 X200 Y215 F7000"
},
"enable_custom_return_speed":
{
"label": "Specify a return speed",
"description": "Set the value below",
"type": "bool",
"default_value": true
},
"return_speed":
{
"label": "return speed in mm/minutes",
"description": "return speed in mm/minute as for the F gcode parameter.",
"type": "int",
"default_value": 7000,
"unit": "mm/m",
"enabled": "enable_custom_return_speed"
},
"pause_length":
{
"label": "Pause length",
"description": "How long to wait (in ms) after camera was triggered.",
"type": "int",
"default_value": 700,
"minimum_value": 0,
"unit": "ms"
},
"enable_retraction":
{
"label": "Enable retraction",
"description": "Retract the filament before moving the head",
"type": "bool",
"default_value": true
},
"retraction_distance":
{
"label": "Retraction distance",
"description": "How much to retract the filament.",
"unit": "mm",
"type": "float",
"default_value": 6.5,
"enabled": "enable_retraction"
},
"display_photo_number":
{
"label": "Display current photo number",
"description": "Display the current photo number on the panel during the shots",
"type": "bool",
"default_value": false
},
"send_photo_command":
{
"label": "Send camera command",
"description": "Display the current photo number on the panel during the shots",
"type": "bool",
"default_value": false
},
"trigger_command":
{
"label": "Trigger camera command",
"description": "Gcode command used to trigger camera.",
"type": "str",
"default_value": "M240",
"enabled": "send_photo_command"
}
}
}"""
# Note : This function and some other bits of code comes from PauseAtHeight.py
# Get the X and Y values for a layer (will be used to get X and Y of the layer after the pause).
def getNextXY(self, layer):
lines = layer.split("\n")
for line in lines:
if self.getValue(line, "G1") and self.getValue(line, "X") is not None and self.getValue(line,
"Y") is not None and self.getValue(line, "E") is not None:
x = self.getValue(line, "X") # new X coordinate
y = self.getValue(line, "Y") # new Y coordinate
e = self.getValue(line, "E") # new E coordinate
return x, y, e
return 100, 100
def execute(self, data):
activate_plugin = self.getSettingValueByKey("activate_plugin")
first_gcode = self.getSettingValueByKey("first_gcode")
second_gcode = self.getSettingValueByKey("second_gcode")
pause_length = self.getSettingValueByKey("pause_length")
enable_custom_return_speed = self.getSettingValueByKey("enable_custom_return_speed")
return_speed = self.getSettingValueByKey("return_speed")
enable_retraction = self.getSettingValueByKey("enable_retraction")
retraction_distance = self.getSettingValueByKey("retraction_distance")
display_photo_number = self.getSettingValueByKey("display_photo_number")
send_photo_command = self.getSettingValueByKey("send_photo_command")
trigger_command = self.getSettingValueByKey("trigger_command")
for layerIndex, layer in enumerate(data):
# Check that a layer is being printed
lines = layer.split("\n")
for line in lines:
if ";LAYER:" in line:
index = data.index(layer)
next_layer = data[layerIndex + 1]
x, y, e = self.getNextXY(next_layer)
gcode_to_append = ""
if activate_plugin:
gcode_to_append += ";CustomTimelapse Begin\n"
if display_photo_number:
gcode_to_append += "M117 Taking photo " + str(layerIndex) + "...\n"
gcode_to_append += "; STEP 1 : retraction\n"
if enable_retraction:
gcode_to_append += self.putValue(G=1, F=1500, E=e-retraction_distance) + ";Retraction\n"
# Printer doing this from itself zhop in cura = true, maybe some oter printer need this
# gcode_to_append += "; STEP 2 : Move the head up a bit\n"
# gcode_to_append += self.putValue(G=91) + ";Switch to relative positioning\n"
# gcode_to_append += self.putValue(G=0, Z=0) + ";Move Z axis up a bit\n"
# gcode_to_append += self.putValue(G=90) + ";Switch back to absolute positioning\n"
gcode_to_append += "; STEP 2 : Move the head to \"display\" position and wait\n"
gcode_to_append += first_gcode + ";GCODE for the first position(display position)\n"
gcode_to_append += self.putValue(M=400) + ";Wait for moves to finish\n"
gcode_to_append += second_gcode + ";GCODE for the second position(trigger position)\n"
gcode_to_append += self.putValue(M=400) + ";Wait for moves to finish\n"
gcode_to_append += self.putValue(G=4, P=pause_length) + ";Wait for camera\n"
gcode_to_append += "; STEP 3 : send photo trigger command if set\n"
if send_photo_command:
gcode_to_append += trigger_command + " ;Snap Photo\n"
gcode_to_append += "; STEP 4 : Move the head back in its original place\n"
if enable_custom_return_speed:
gcode_to_append += self.putValue(G=0, X=x, Y=y, F=return_speed) + "\n"
gcode_to_append += self.putValue(M=400) + "\n"
gcode_to_append += self.putValue(G=0, X=x, Y=y, F=1500) + "\n"
else:
gcode_to_append += self.putValue(G=0, X=x, Y=y) + "\n"
gcode_to_append += ";CustomTimelapse End\n"
layer += gcode_to_append
data[index] = layer
break
return data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment