chiark / gitweb /
Set the new minimal-extrusion-before-retraction default.
[cura.git] / Cura / cura.py
1 #!/usr/bin/python
2 """
3 This page is in the table of contents.
4 ==Overview==
5 ===Introduction===
6 Cura is a AGPL tool chain to generate a GCode path for 3D printing. Older versions of Cura where based on Skeinforge.
7 Versions up from 13.05 are based on a C++ engine called CuraEngine.
8 """
9 from __future__ import absolute_import
10 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
11
12 from optparse import OptionParser
13
14 from Cura.util import profile
15
16 def main():
17         parser = OptionParser(usage="usage: %prog [options] <filename>.stl")
18         parser.add_option("-i", "--ini", action="store", type="string", dest="profileini",
19                 help="Load settings from a profile ini file")
20         parser.add_option("-r", "--print", action="store", type="string", dest="printfile",
21                 help="Open the printing interface, instead of the normal cura interface.")
22         parser.add_option("-p", "--profile", action="store", type="string", dest="profile",
23                 help="Internal option, do not use!")
24         parser.add_option("-s", "--slice", action="store_true", dest="slice",
25                 help="Slice the given files instead of opening them in Cura")
26         parser.add_option("-o", "--output", action="store", type="string", dest="output",
27                 help="path to write sliced file to")
28
29         (options, args) = parser.parse_args()
30
31         profile.loadPreferences(profile.getPreferencePath())
32         if options.profile is not None:
33                 profile.setProfileFromString(options.profile)
34         elif options.profileini is not None:
35                 profile.loadProfile(options.profileini)
36         else:
37                 profile.loadProfile(profile.getDefaultProfilePath())
38
39         if options.printfile is not None:
40                 from Cura.gui import printWindow
41                 printWindow.startPrintInterface(options.printfile)
42         elif options.slice is not None:
43                 from Cura.util import sliceEngine
44                 from Cura.util import objectScene
45                 from Cura.util import meshLoader
46                 import shutil
47
48                 def commandlineProgressCallback(progress, ready):
49                         if progress >= 0 and not ready:
50                                 print 'Preparing: %d%%' % (progress * 100)
51                 scene = objectScene.Scene()
52                 scene.updateMachineDimensions()
53                 slicer = sliceEngine.Slicer(commandlineProgressCallback)
54                 for m in meshLoader.loadMeshes(args[0]):
55                         scene.add(m)
56                 slicer.runSlicer(scene)
57                 slicer.wait()
58                 profile.replaceGCodeTagsFromSlicer(slicer.getGCodeFilename(), slicer)
59
60                 if options.output:
61                         shutil.copyfile(slicer.getGCodeFilename(), options.output)
62                         print 'GCode file saved : %s' % options.output
63                 else:
64                         shutil.copyfile(slicer.getGCodeFilename(), args[0] + '.gcode')
65                         print 'GCode file saved as: %s' % (args[0] + '.gcode')
66
67                 slicer.cleanup()
68         else:
69                 from Cura.gui import app
70                 app.CuraApp(args).MainLoop()
71
72 if __name__ == '__main__':
73         main()