Jump to content

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)

p.startprint(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

    Hi,

    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

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

    Hi rapcsak, did you manage to get the code working. I am trying to do the same thing, so it would be nice to know if this might work or not.

  • 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 5.9 stable released!
        Here comes Cura 5.9 and in this stable release we have lots of material and printer profiles for UltiMaker printers, including the newly released Sketch Sprint. Additionally, scarf seams have been introduced alongside even more print settings and improvements.  Check out the rest of this article to find out the details on all of that and more
          • Like
        • 5 replies
      • Introducing the UltiMaker Factor 4
        We are happy to announce the next evolution in the UltiMaker 3D printer lineup: the UltiMaker Factor 4 industrial-grade 3D printer, designed to take manufacturing to new levels of efficiency and reliability. Factor 4 is an end-to-end 3D printing solution for light industrial applications
          • Heart
          • Thanks
          • Like
        • 4 replies
    ×
    ×
    • Create New...