Jump to content

Help Required For Calling CuraEngline From Python For Command Line Tool


rapcsak

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.7 stable released
        Cura 5.7 is here and it brings a handy new workflow improvement when using Thingiverse and Cura together, as well as additional capabilities for Method series printers, and a powerful way of sharing print settings using new printer-agnostic project files! Read on to find out about all of these improvements and more. 
         
          • Like
        • 7 replies
      • S-Line Firmware 8.3.0 was released Nov. 20th on the "Latest" firmware branch.
        (Sorry, was out of office when this released)

        This update is for...
        All UltiMaker S series  
        New features
         
        Temperature status. During print preparation, the temperatures of the print cores and build plate will be shown on the display. This gives a better indication of the progress and remaining wait time. Save log files in paused state. It is now possible to save the printer's log files to USB if the currently active print job is paused. Previously, the Dump logs to USB option was only enabled if the printer was in idle state. Confirm print removal via Digital Factory. If the printer is connected to the Digital Factory, it is now possible to confirm the removal of a previous print job via the Digital Factory interface. This is useful in situations where the build plate is clear, but the operator forgot to select Confirm removal on the printer’s display. Visit this page for more information about this feature.
          • Like
        • 0 replies
    ×
    ×
    • Create New...