Jump to content
rapcsak

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!

Share this post


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.

 

Share this post


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

Thanks a lot for your reply, I'll try to do it this way!

Share this post


Link to post
Share on other sites
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.

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Our picks

    • Ultimaker Cura 4.0 | Stable available!
      Ultimaker Cura 4.0 is mainly focused on the improved user interface and cloud integration.
      As always, we want to collect your user feedback for this release. If there are any improvements you can think of, feel free to mention it here and help us to shape the next release.
      • 96 replies
×
×
  • Create New...

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!