Jump to content
Ultimaker Community of 3D Printing Experts

Easiest way to turn on/off my laser for G0 moves then turn it back on for G1 draws using Cura???

Recommended Posts

I am using code to turn my laser on and off but need a way to get Cura to insert the code at the appropriate times.

I have been hand editing the g-code and inserting the code by hand which is getting tedious!

Each time I want the laser to turn off I put this code in:

G4 P0050 ; Pauses for 50 ms. This makes sure that the last move command executes before the laser turns off.

M104 S0 T2 ; Sets the #3 extruder heater output to off.

G0 Xnnn Ynnn ; General command for a non-printing move.

Each time I want the laser back on:

G4 P0050 ; pause

M104 S50 T2 ; Sets temp above threashold so it activates Laser to turn on.

G4 P0500 ; pauses a short 50ms so Laser can get fully turned on




Share this post

Link to post
Share on other sites


You could use a plugin in Cura, don't know if this worked, but an intern tried this a year ago:

other option is to use regular expressions in a better text editor:


G0 (.*)



G0 /1

[btw, i am not a programmer, but i really like google and copy/paste...]

cheers \ joris

#Name: Powder Printing

#Info: Switch off fan power during travel moves

#Help: PowderPrinting

#Depend: GCode

#Type: postprocess

#Param: fanpowermin(int:) Fan Power Min(0-255)

#Param: fanpowermax(int:) Fan Power Max(0-255)

## Written by Tom Kerckhaert, based on TweakAtZ by Steven Morlock

## Special Thanks to Joris van Tubergen

## This script is licensed under the Creative Commons - Attribution - Share Alike (CC BY-SA) terms

# Uses - Switch off fan power during travel moves


# Get rid of the unnecessary fan on / off between two G moves

# Fan power variables do not work yet

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 == None:

return default


return float(m.group(0))


return default

with open(filename, "r") as f:

lines = f.readlines()

with open(filename, "w") as f:

for line in lines:

if getValue(line, 'G', None) == 0:

f.write("; Powder Plugin\n")

f.write("M106 S0\n")


f.write("M106 S255\n")

f.write("; Plugin: End\n")


if getValue(line, 'G', None) == 1:

x = getValue(line, 'X', dx)

y = getValue(line, 'Y', dy)

z = getValue(line, 'Z', dz)

e = getValue(line, 'E', e)

f = getValue(line, 'F', f)

line = 'G1 '

if dx != x:

line += 'X%f ' % x

if dy != y:

line += 'Y%f ' % y

if dz != z:

line += 'Z%f ' % z

if df != f:

line += 'F%f ' % f

line += '\n'


# if comment is the extruder movements before and after the print, remove that line


Share this post

Link to post
Share on other sites

Yes, what Joris said. Write a plugin. It will be awesome. And please share it! Note also that the newest versions of Cura (15.06.* and newer) have a totally different way of doing plugins and I don't know if anyone knows how to do that yet so I would go for the older version e.g. 15.04 and I'm sure all the work you did for the plugin will still be useful - I suspect converting plugins from 15.04 to 15.06 will be pretty simple once someone documents the process.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Our picks

    • Ultimaker Cura | a new interface
      We're not only trying to always make Ultimaker Cura better with the usual new features and improvements we build, but we're also trying to make it more pleasant to operate. The interface was the focus for the upcoming release, from which we would already like to present you the first glance. 
        • Like
      • 130 replies
    • "Back To The Future" using Generative Design & Investment Casting
      Designing for light-weight parts is becoming more important, and I’m a firm believer in the need to produce lighter weight, less over-engineered parts for the future. This is for sustainability reasons because we need to be using less raw materials and, in things like transportation, it impacts the energy usage of the product during it’s service life.
        • Like
      • 12 replies

Important Information

Welcome to the Ultimaker Community of 3D printing experts. Visit the following links to read more about our Terms of Use or our Privacy Policy. Thank you!