chiark / gitweb /
a475705b28b610cfd2eedf6f5b8a74c0a6fc1f42
[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 resources
15 resources.setupLocalization()  # it's important to set up localization at very beginning to install _
16 from Cura.util import profile
17
18 def main():
19         parser = OptionParser(usage="usage: %prog [options] <filename>.stl")
20         parser.add_option("-i", "--ini", action="store", type="string", dest="profileini",
21                 help="Load settings from a profile ini file")
22         parser.add_option("-r", "--print", action="store", type="string", dest="printfile",
23                 help="Open the printing interface, instead of the normal cura interface.")
24         parser.add_option("-p", "--profile", action="store", type="string", dest="profile",
25                 help="Internal option, do not use!")
26         parser.add_option("-s", "--slice", action="store_true", dest="slice",
27                 help="Slice the given files instead of opening them in Cura")
28         parser.add_option("-o", "--output", action="store", type="string", dest="output",
29                 help="path to write sliced file to")
30
31         (options, args) = parser.parse_args()
32
33         profile.loadPreferences(profile.getPreferencePath())
34         if options.profile is not None:
35                 profile.loadProfileFromString(options.profile)
36         elif options.profileini is not None:
37                 profile.loadProfile(options.profileini)
38         else:
39                 profile.loadProfile(profile.getDefaultProfilePath())
40
41         if options.printfile is not None:
42                 from Cura.gui import printWindow
43                 printWindow.startPrintInterface(options.printfile)
44         elif options.slice is not None:
45                 from Cura.util import sliceEngine
46                 from Cura.util import objectScene
47                 from Cura.util import meshLoader
48                 import shutil
49
50                 def commandlineProgessCallback(progress, ready):
51                         if progress >= 0 and not ready:
52                                 print 'Preparing: %d%%' % (progress * 100)
53                 scene = objectScene.Scene()
54                 slicer = sliceEngine.Slicer(commandlineProgessCallback)
55                 for m in meshLoader.loadMeshes(args[0]):
56                         scene.add(m)
57                 slicer.runSlicer(scene)
58                 slicer.wait()
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()