slic3r.pl 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. BEGIN {
  5. use FindBin;
  6. use lib "$FindBin::Bin/lib";
  7. }
  8. use Getopt::Long qw(:config no_auto_abbrev);
  9. use List::Util qw(first);
  10. use Slic3r;
  11. $|++;
  12. our %opt = ();
  13. my %cli_options = ();
  14. {
  15. my %options = (
  16. 'help' => sub { usage() },
  17. 'version' => sub { print "$Slic3r::VERSION\n"; exit 0 },
  18. 'debug' => \$Slic3r::debug,
  19. 'gui' => \$opt{gui},
  20. 'o|output=s' => \$opt{output},
  21. 'save=s' => \$opt{save},
  22. 'load=s@' => \$opt{load},
  23. 'ignore-nonexistent-config' => \$opt{ignore_nonexistent_config},
  24. 'datadir=s' => \$opt{datadir},
  25. 'export-svg' => \$opt{export_svg},
  26. 'merge|m' => \$opt{merge},
  27. );
  28. foreach my $opt_key (keys %{$Slic3r::Config::Options}) {
  29. my $cli = $Slic3r::Config::Options->{$opt_key}->{cli} or next;
  30. # allow both the dash-separated option name and the full opt_key
  31. $options{ "$opt_key|$cli" } = \$cli_options{$opt_key};
  32. }
  33. GetOptions(%options) or usage(1);
  34. }
  35. # process command line options
  36. my $cli_config = Slic3r::Config->new_from_cli(%cli_options);
  37. # load configuration files
  38. my @external_configs = ();
  39. if ($opt{load}) {
  40. foreach my $configfile (@{$opt{load}}) {
  41. if (-e $configfile) {
  42. push @external_configs, Slic3r::Config->load($configfile);
  43. } elsif (-e "$FindBin::Bin/$configfile") {
  44. printf STDERR "Loading $FindBin::Bin/$configfile\n";
  45. push @external_configs, Slic3r::Config->load("$FindBin::Bin/$configfile");
  46. } else {
  47. $opt{ignore_nonexistent_config} or die "Cannot find specified configuration file ($configfile).\n";
  48. }
  49. }
  50. }
  51. # merge configuration
  52. my $config = Slic3r::Config->new_from_defaults;
  53. $config->apply($_) for @external_configs, $cli_config;
  54. # save configuration
  55. if ($opt{save}) {
  56. $config->validate;
  57. $config->save($opt{save});
  58. }
  59. # launch GUI
  60. my $gui;
  61. if (!@ARGV && !$opt{save} && eval "require Slic3r::GUI; 1") {
  62. {
  63. no warnings 'once';
  64. $Slic3r::GUI::datadir = $opt{datadir} if $opt{datadir};
  65. }
  66. $gui = Slic3r::GUI->new;
  67. $gui->{skeinpanel}->load_config_file($_) for @{$opt{load}};
  68. $gui->{skeinpanel}->load_config($cli_config);
  69. $gui->MainLoop;
  70. exit;
  71. }
  72. die $@ if $@ && $opt{gui};
  73. if (@ARGV) { # slicing from command line
  74. $config->validate;
  75. while (my $input_file = shift @ARGV) {
  76. my $print = Slic3r::Print->new(config => $config);
  77. $print->add_model(Slic3r::Model->read_from_file($input_file));
  78. if ($opt{merge}) {
  79. $print->add_model(Slic3r::Model->read_from_file($_)) for splice @ARGV, 0;
  80. }
  81. $print->duplicate;
  82. $print->arrange_objects if @{$print->objects} > 1;
  83. $print->validate;
  84. my %params = (
  85. output_file => $opt{output},
  86. status_cb => sub {
  87. my ($percent, $message) = @_;
  88. printf "=> %s\n", $message;
  89. },
  90. );
  91. if ($opt{export_svg}) {
  92. $print->export_svg(%params);
  93. } else {
  94. $print->export_gcode(%params);
  95. }
  96. }
  97. } else {
  98. usage(1) unless $opt{save};
  99. }
  100. sub usage {
  101. my ($exit_code) = @_;
  102. my $config = Slic3r::Config->new_from_defaults;
  103. my $j = '';
  104. if ($Slic3r::have_threads) {
  105. $j = <<"EOF";
  106. -j, --threads <num> Number of threads to use (1+, default: $config->{threads})
  107. EOF
  108. }
  109. print <<"EOF";
  110. Slic3r $Slic3r::VERSION is a STL-to-GCODE translator for RepRap 3D printers
  111. written by Alessandro Ranellucci <aar\@cpan.org> - http://slic3r.org/
  112. Usage: slic3r.pl [ OPTIONS ] file.stl
  113. --help Output this usage screen and exit
  114. --version Output the version of Slic3r and exit
  115. --save <file> Save configuration to the specified file
  116. --load <file> Load configuration from the specified file. It can be used
  117. more than once to load options from multiple files.
  118. -o, --output <file> File to output gcode to (by default, the file will be saved
  119. into the same directory as the input file using the
  120. --output-filename-format to generate the filename)
  121. $j
  122. Output options:
  123. --output-filename-format
  124. Output file name format; all config options enclosed in brackets
  125. will be replaced by their values, as well as [input_filename_base]
  126. and [input_filename] (default: $config->{output_filename_format})
  127. --post-process Generated G-code will be processed with the supplied script;
  128. call this more than once to process through multiple scripts.
  129. --export-svg Export a SVG file containing slices instead of G-code.
  130. -m, --merge If multiple files are supplied, they will be composed into a single
  131. print rather than processed individually.
  132. Printer options:
  133. --nozzle-diameter Diameter of nozzle in mm (default: $config->{nozzle_diameter}->[0])
  134. --print-center Coordinates in mm of the point to center the print around
  135. (default: $config->{print_center}->[0],$config->{print_center}->[1])
  136. --z-offset Additional height in mm to add to vertical coordinates
  137. (+/-, default: $config->{z_offset})
  138. --gcode-flavor The type of G-code to generate (reprap/teacup/makerbot/mach3/no-extrusion,
  139. default: $config->{gcode_flavor})
  140. --use-relative-e-distances Enable this to get relative E values
  141. --gcode-arcs Use G2/G3 commands for native arcs (experimental, not supported
  142. by all firmwares)
  143. --g0 Use G0 commands for retraction (experimental, not supported by all
  144. firmwares)
  145. --gcode-comments Make G-code verbose by adding comments (default: no)
  146. Filament options:
  147. --filament-diameter Diameter in mm of your raw filament (default: $config->{filament_diameter}->[0])
  148. --extrusion-multiplier
  149. Change this to alter the amount of plastic extruded. There should be
  150. very little need to change this value, which is only useful to
  151. compensate for filament packing (default: $config->{extrusion_multiplier}->[0])
  152. --temperature Extrusion temperature in degree Celsius, set 0 to disable (default: $config->{temperature}->[0])
  153. --first-layer-temperature Extrusion temperature for the first layer, in degree Celsius,
  154. set 0 to disable (default: same as --temperature)
  155. --bed-temperature Heated bed temperature in degree Celsius, set 0 to disable (default: $config->{bed_temperature})
  156. --first-layer-bed-temperature Heated bed temperature for the first layer, in degree Celsius,
  157. set 0 to disable (default: same as --bed-temperature)
  158. Speed options:
  159. --travel-speed Speed of non-print moves in mm/s (default: $config->{travel_speed})
  160. --perimeter-speed Speed of print moves for perimeters in mm/s (default: $config->{perimeter_speed})
  161. --small-perimeter-speed
  162. Speed of print moves for small perimeters in mm/s or % over perimeter speed
  163. (default: $config->{small_perimeter_speed})
  164. --external-perimeter-speed
  165. Speed of print moves for the external perimeter in mm/s or % over perimeter speed
  166. (default: $config->{external_perimeter_speed})
  167. --infill-speed Speed of print moves in mm/s (default: $config->{infill_speed})
  168. --solid-infill-speed Speed of print moves for solid surfaces in mm/s or % over infill speed
  169. (default: $config->{solid_infill_speed})
  170. --top-solid-infill-speed Speed of print moves for top surfaces in mm/s or % over solid infill speed
  171. (default: $config->{top_solid_infill_speed})
  172. --bridge-speed Speed of bridge print moves in mm/s (default: $config->{bridge_speed})
  173. --first-layer-speed Speed of print moves for bottom layer, expressed either as an absolute
  174. value or as a percentage over normal speeds (default: $config->{first_layer_speed})
  175. Accuracy options:
  176. --layer-height Layer height in mm (default: $config->{layer_height})
  177. --first-layer-height Layer height for first layer (mm or %, default: $config->{first_layer_height})
  178. --infill-every-layers
  179. Infill every N layers (default: $config->{infill_every_layers})
  180. --solid-infill-every-layers
  181. Force a solid layer every N layers (default: $config->{solid_infill_every_layers})
  182. Print options:
  183. --perimeters Number of perimeters/horizontal skins (range: 0+, default: $config->{perimeters})
  184. --top-solid-layers Number of solid layers to do for top surfaces (range: 0+, default: $config->{top_solid_layers})
  185. --bottom-solid-layers Number of solid layers to do for bottom surfaces (range: 0+, default: $config->{bottom_solid_layers})
  186. --solid-layers Shortcut for setting the two options above at once
  187. --fill-density Infill density (range: 0-1, default: $config->{fill_density})
  188. --fill-angle Infill angle in degrees (range: 0-90, default: $config->{fill_angle})
  189. --fill-pattern Pattern to use to fill non-solid layers (default: $config->{fill_pattern})
  190. --solid-fill-pattern Pattern to use to fill solid layers (default: $config->{solid_fill_pattern})
  191. --start-gcode Load initial G-code from the supplied file. This will overwrite
  192. the default command (home all axes [G28]).
  193. --end-gcode Load final G-code from the supplied file. This will overwrite
  194. the default commands (turn off temperature [M104 S0],
  195. home X axis [G28 X], disable motors [M84]).
  196. --layer-gcode Load layer-change G-code from the supplied file (default: nothing).
  197. --extra-perimeters Add more perimeters when needed (default: yes)
  198. --randomize-start Randomize starting point across layers (default: yes)
  199. --only-retract-when-crossing-perimeters
  200. Disable retraction when travelling between infill paths inside the same island.
  201. (default: no)
  202. --solid-infill-below-area
  203. Force solid infill when a region has a smaller area than this threshold
  204. (mm^2, default: $config->{solid_infill_below_area})
  205. Support material options:
  206. --support-material Generate support material for overhangs
  207. --support-material-threshold
  208. Overhang threshold angle (range: 0-90, default: $config->{support_material_threshold})
  209. --support-material-pattern
  210. Pattern to use for support material (default: $config->{support_material_pattern})
  211. --support-material-spacing
  212. Spacing between pattern lines (mm, default: $config->{support_material_spacing})
  213. --support-material-angle
  214. Support material angle in degrees (range: 0-90, default: $config->{support_material_angle})
  215. Retraction options:
  216. --retract-length Length of retraction in mm when pausing extrusion (default: $config->{retract_length}[0])
  217. --retract-speed Speed for retraction in mm/s (default: $config->{retract_speed}[0])
  218. --retract-restart-extra
  219. Additional amount of filament in mm to push after
  220. compensating retraction (default: $config->{retract_restart_extra}[0])
  221. --retract-before-travel
  222. Only retract before travel moves of this length in mm (default: $config->{retract_before_travel}[0])
  223. --retract-lift Lift Z by the given distance in mm when retracting (default: $config->{retract_lift}[0])
  224. Retraction options for multi-extruder setups:
  225. --retract-length-toolchange
  226. Length of retraction in mm when disabling tool (default: $config->{retract_length}[0])
  227. --retract-restart-extra-toolchnage
  228. Additional amount of filament in mm to push after
  229. switching tool (default: $config->{retract_restart_extra}[0])
  230. Cooling options:
  231. --cooling Enable fan and cooling control
  232. --min-fan-speed Minimum fan speed (default: $config->{min_fan_speed}%)
  233. --max-fan-speed Maximum fan speed (default: $config->{max_fan_speed}%)
  234. --bridge-fan-speed Fan speed to use when bridging (default: $config->{bridge_fan_speed}%)
  235. --fan-below-layer-time Enable fan if layer print time is below this approximate number
  236. of seconds (default: $config->{fan_below_layer_time})
  237. --slowdown-below-layer-time Slow down if layer print time is below this approximate number
  238. of seconds (default: $config->{slowdown_below_layer_time})
  239. --min-print-speed Minimum print speed (mm/s, default: $config->{min_print_speed})
  240. --disable-fan-first-layers Disable fan for the first N layers (default: $config->{disable_fan_first_layers})
  241. --fan-always-on Keep fan always on at min fan speed, even for layers that don't need
  242. cooling
  243. Skirt options:
  244. --skirts Number of skirts to draw (0+, default: $config->{skirts})
  245. --skirt-distance Distance in mm between innermost skirt and object
  246. (default: $config->{skirt_distance})
  247. --skirt-height Height of skirts to draw (expressed in layers, 0+, default: $config->{skirt_height})
  248. --brim-width Width of the brim that will get added to each object to help adhesion
  249. (mm, default: $config->{brim_width})
  250. Transform options:
  251. --scale Factor for scaling input object (default: $config->{scale})
  252. --rotate Rotation angle in degrees (0-360, default: $config->{rotate})
  253. --duplicate Number of items with auto-arrange (1+, default: $config->{duplicate})
  254. --bed-size Bed size, only used for auto-arrange (mm, default: $config->{bed_size}->[0],$config->{bed_size}->[1])
  255. --duplicate-grid Number of items with grid arrangement (default: $config->{duplicate_grid}->[0],$config->{duplicate_grid}->[1])
  256. --duplicate-distance Distance in mm between copies (default: $config->{duplicate_distance})
  257. Sequential printing options:
  258. --complete-objects When printing multiple objects and/or copies, complete each one before
  259. starting the next one; watch out for extruder collisions (default: no)
  260. --extruder-clearance-radius Radius in mm above which extruder won't collide with anything
  261. (default: $config->{extruder_clearance_radius})
  262. --extruder-clearance-height Maximum vertical extruder depth; i.e. vertical distance from
  263. extruder tip and carriage bottom (default: $config->{extruder_clearance_height})
  264. Miscellaneous options:
  265. --notes Notes to be added as comments to the output file
  266. Flow options (advanced):
  267. --extrusion-width Set extrusion width manually; it accepts either an absolute value in mm
  268. (like 0.65) or a percentage over layer height (like 200%)
  269. --first-layer-extrusion-width
  270. Set a different extrusion width for first layer
  271. --perimeters-extrusion-width
  272. Set a different extrusion width for perimeters
  273. --infill-extrusion-width
  274. Set a different extrusion width for infill
  275. --support-material-extrusion-width
  276. Set a different extrusion width for support material
  277. --bridge-flow-ratio Multiplier for extrusion when bridging (> 0, default: $config->{bridge_flow_ratio})
  278. Multiple extruder options:
  279. --extruder-offset Offset of each extruder, if firmware doesn't handle the displacement
  280. (can be specified multiple times, default: 0x0)
  281. --perimeters-extruder
  282. Extruder to use for perimeters (1+, default: 1)
  283. --infill-extruder Extruder to use for infill (1+, default: 1)
  284. --support-material-extruder
  285. Extruder to use for support material (1+, default: 1)
  286. EOF
  287. exit ($exit_code || 0);
  288. }
  289. __END__