Jump to content
Ultimaker Community of 3D Printing Experts

Help Required For Calling CuraEngline From Python For Command Line Tool

Recommended Posts

Posted · Help Required For Calling CuraEngline From Python For Command Line Tool

I am trying to build a command line application that converts a given stl file into gcode and launches the print automatically. For this, I write the code in Python, and use CuraEngine and Printcore:

import subprocess

import xmlrpclib

import sys

import time

from printrun.printcore import printcore

from printrun import gcoder

curaEngine = "C:/Desktop/CuraEnginePacket/CuraEngine"

JSONfile = "C:/Desktop/CuraResources/machines/ultimaker2plus.json"

myGcode = "C:Desktop/mygcode.gcode"

myStl = "C:/Desktop/XX.stl"

p = printcore('COM6', 250000)

command = [curaEngine, 'slice', '-j', JSONfile, '-o', myGcode, '-l', myStl]

return_code = subprocess.call(command)

gcode = [i.strip() for i in open(myGcode)]

gcode = gcoder.LightGCode(gcode)


When I tested the program, it started the print, but the printer head was just moving back and forth and no material came out of it. As a check, I loaded my stl-file in Cura, and compared the resulting gcode to the one generated by CuraEngine. Surprisingly, they did differ to a huge extent. The -- START GCODE -- and -- END GCODE -- sections were not included in the gcode created by CuraEngine, furthermore the coordinates were slightly different as well.

Have I called CuraEngine correctly in Python? How could I make my program add the missing sections to the gcode?

Thanks a lot for your attention to the problem!

  • Link to post
    Share on other sites
    Posted · Help Required For Calling CuraEngline From Python For Command Line Tool


    I have basically the exactly same issue since i am working on something related.

    You have to download and compile the latest CuraEngine version. This one does output the gcode header after the file has been sliced. You then need to process the output of CuraEngine, extract the last bit with the new gcode header and replace the gcode header in your .gcode file with it.

    There are TONS of slicing parameters which CuraEngine supports. If you don't specify any, you get the minimal default which is not really what you want.

    In order to get a proper list of parameters I suggest you do the following:


    1. Use Cura Desktop 2.3.0 to slice a model the way you like it.
    2. Take a look at the cura.log file to see which slicing parameters Cura Desktop used to slice it (since Cura Desktop acts as a very sophisticated frontend for CuraEngine it sends all slicing options in one go (every parameters prepended by "-s")). On my Mac the cura.log file resides at ~/Library/Application Support/Cura/cura.log
    3. Save the slicing parameters to a text file and append its contents to your CuraEngine call.


  • Link to post
    Share on other sites
    • 1 year later...
    Posted · Help Required For Calling CuraEngline From Python For Command Line Tool

    Hi NicoLinux,

    I have been trying to capture the filament length and time from the, "Gcode header after slicing". But apparently, the updated header does not show up in the output for the command

    `CuraEngine slice -v -p -j fdmprinter.def.json -l #{model_url}`

    Seems the header is generated after the gcode, which is not captured in the output.

    How could I get the final, filament and time parameters.


  • 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
    • Create New...