Jump to content
Ultimaker Community of 3D Printing Experts
rapcsak

Help Required For Calling CuraEngline From Python For Command Line Tool

Recommended Posts

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!

Share this post


Link to post
Share on other sites

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.

 

Share this post


Link to post
Share on other sites

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.

 

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

    • Introducing Ultimaker Cura 3.6 | Beta
      Ultimaker Cura 3.6 | Beta is available. It comes with new features, bug fixes, and UX improvements. We would really like to have your feedback on it to make our stable release as good as it can be. As always, you can download the beta for free from our website, for Windows, MacOS, and Linux.
        • Like
      • 95 replies
    • Print Core CC | Red for Ruby
      Q: For some users, abrasive materials may be a new subject matter. Can you explain what it is that makes a material abrasive when you are not sure which print core to use?
      A: Materials which are hard in a solid piece (like metals, ceramics and carbon fibers) will generally also wear down the nozzle. In general one should assume...
        • Like
      • 30 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!