slic3r.pl 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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 POSIX qw(setlocale LC_NUMERIC);
  11. use Slic3r;
  12. use Time::HiRes qw(gettimeofday tv_interval);
  13. $|++;
  14. our %opt = ();
  15. my %cli_options = ();
  16. {
  17. my %options = (
  18. 'help' => sub { usage() },
  19. 'version' => sub { print "$Slic3r::VERSION\n"; exit 0 },
  20. 'debug' => \$Slic3r::debug,
  21. 'gui' => \$opt{gui},
  22. 'o|output=s' => \$opt{output},
  23. 'save=s' => \$opt{save},
  24. 'load=s@' => \$opt{load},
  25. 'autosave=s' => \$opt{autosave},
  26. 'ignore-nonexistent-config' => \$opt{ignore_nonexistent_config},
  27. 'no-plater' => \$opt{no_plater},
  28. 'gui-mode=s' => \$opt{gui_mode},
  29. 'datadir=s' => \$opt{datadir},
  30. 'export-svg' => \$opt{export_svg},
  31. 'merge|m' => \$opt{merge},
  32. 'repair' => \$opt{repair},
  33. 'info' => \$opt{info},
  34. 'scale=f' => \$opt{scale},
  35. 'rotate=i' => \$opt{rotate},
  36. 'duplicate=i' => \$opt{duplicate},
  37. 'duplicate-grid=s' => \$opt{duplicate_grid},
  38. );
  39. foreach my $opt_key (keys %{$Slic3r::Config::Options}) {
  40. my $cli = $Slic3r::Config::Options->{$opt_key}->{cli} or next;
  41. # allow both the dash-separated option name and the full opt_key
  42. $options{ "$opt_key|$cli" } = \$cli_options{$opt_key};
  43. }
  44. GetOptions(%options) or usage(1);
  45. }
  46. # process command line options
  47. my $cli_config = Slic3r::Config->new_from_cli(%cli_options);
  48. # load configuration files
  49. my @external_configs = ();
  50. if ($opt{load}) {
  51. foreach my $configfile (@{$opt{load}}) {
  52. if (-e $configfile) {
  53. push @external_configs, Slic3r::Config->load($configfile);
  54. } elsif (-e "$FindBin::Bin/$configfile") {
  55. printf STDERR "Loading $FindBin::Bin/$configfile\n";
  56. push @external_configs, Slic3r::Config->load("$FindBin::Bin/$configfile");
  57. } else {
  58. $opt{ignore_nonexistent_config} or die "Cannot find specified configuration file ($configfile).\n";
  59. }
  60. }
  61. }
  62. # merge configuration
  63. my $config = Slic3r::Config->new_from_defaults;
  64. $config->apply($_) for @external_configs, $cli_config;
  65. # save configuration
  66. if ($opt{save}) {
  67. $config->validate;
  68. $config->save($opt{save});
  69. }
  70. # launch GUI
  71. my $gui;
  72. if (!@ARGV && !$opt{save} && eval "require Slic3r::GUI; 1") {
  73. {
  74. no warnings 'once';
  75. $Slic3r::GUI::datadir = $opt{datadir};
  76. $Slic3r::GUI::no_plater = $opt{no_plater};
  77. $Slic3r::GUI::mode = $opt{gui_mode};
  78. $Slic3r::GUI::autosave = $opt{autosave};
  79. }
  80. $gui = Slic3r::GUI->new;
  81. setlocale(LC_NUMERIC, 'C');
  82. $gui->{skeinpanel}->load_config_file($_) for @{$opt{load}};
  83. $gui->{skeinpanel}->load_config($cli_config);
  84. $gui->MainLoop;
  85. exit;
  86. }
  87. die $@ if $@ && $opt{gui};
  88. if (@ARGV) { # slicing from command line
  89. $config->validate;
  90. if ($opt{repair}) {
  91. foreach my $file (@ARGV) {
  92. die "Repair is currently supported only on STL files\n"
  93. if $file !~ /\.stl$/i;
  94. my $output_file = $file;
  95. $output_file =~ s/\.(stl)$/_fixed.obj/i;
  96. my $tmesh = Slic3r::TriangleMesh->new;
  97. $tmesh->ReadSTLFile($file);
  98. $tmesh->repair;
  99. $tmesh->WriteOBJFile($output_file);
  100. }
  101. exit;
  102. }
  103. while (my $input_file = shift @ARGV) {
  104. my $model;
  105. if ($opt{merge}) {
  106. my @models = map Slic3r::Model->read_from_file($_), $input_file, (splice @ARGV, 0);
  107. $model = Slic3r::Model->merge(@models);
  108. } else {
  109. $model = Slic3r::Model->read_from_file($input_file);
  110. }
  111. if ($opt{info}) {
  112. $model->print_info;
  113. next;
  114. }
  115. if (defined $opt{duplicate_grid}) {
  116. $opt{duplicate_grid} = [ split /[,x]/, $opt{duplicate_grid}, 2 ];
  117. }
  118. my $sprint = Slic3r::Print::Simple->new(
  119. scale => $opt{scale} // 1,
  120. rotate => $opt{rotate} // 0,
  121. duplicate => $opt{duplicate} // 1,
  122. duplicate_grid => $opt{duplicate_grid} // [1,1],
  123. status_cb => sub {
  124. my ($percent, $message) = @_;
  125. printf "=> %s\n", $message;
  126. },
  127. output_file => $opt{output},
  128. );
  129. $sprint->apply_config($config);
  130. $sprint->set_model($model);
  131. undef $model; # free memory
  132. if ($opt{export_svg}) {
  133. $sprint->export_svg;
  134. } else {
  135. my $t0 = [gettimeofday];
  136. $sprint->export_gcode;
  137. # output some statistics
  138. {
  139. my $duration = tv_interval($t0);
  140. printf "Done. Process took %d minutes and %.3f seconds\n",
  141. int($duration/60), ($duration - int($duration/60)*60); # % truncates to integer
  142. }
  143. printf "Filament required: %.1fmm (%.1fcm3)\n",
  144. $sprint->total_used_filament, $sprint->total_extruded_volume/1000;
  145. }
  146. }
  147. } else {
  148. usage(1) unless $opt{save};
  149. }
  150. sub usage {
  151. my ($exit_code) = @_;
  152. my $config = Slic3r::Config->new_from_defaults->as_hash;
  153. my $j = '';
  154. if ($Slic3r::have_threads) {
  155. $j = <<"EOF";
  156. -j, --threads <num> Number of threads to use (1+, default: $config->{threads})
  157. EOF
  158. }
  159. print <<"EOF";
  160. Slic3r $Slic3r::VERSION is a STL-to-GCODE translator for RepRap 3D printers
  161. written by Alessandro Ranellucci <aar\@cpan.org> - http://slic3r.org/
  162. Usage: slic3r.pl [ OPTIONS ] [ file.stl ] [ file2.stl ] ...
  163. --help Output this usage screen and exit
  164. --version Output the version of Slic3r and exit
  165. --save <file> Save configuration to the specified file
  166. --load <file> Load configuration from the specified file. It can be used
  167. more than once to load options from multiple files.
  168. -o, --output <file> File to output gcode to (by default, the file will be saved
  169. into the same directory as the input file using the
  170. --output-filename-format to generate the filename)
  171. Non-slicing actions (no G-code will be generated):
  172. --repair Repair given STL files and save them as <name>_fixed.obj
  173. --info Output information about the supplied file(s) and exit
  174. $j
  175. GUI options:
  176. --no-plater Disable the plater tab
  177. --gui-mode Overrides the configured mode (simple/expert)
  178. --autosave <file> Automatically export current configuration to the specified file
  179. Output options:
  180. --output-filename-format
  181. Output file name format; all config options enclosed in brackets
  182. will be replaced by their values, as well as [input_filename_base]
  183. and [input_filename] (default: $config->{output_filename_format})
  184. --post-process Generated G-code will be processed with the supplied script;
  185. call this more than once to process through multiple scripts.
  186. --export-svg Export a SVG file containing slices instead of G-code.
  187. -m, --merge If multiple files are supplied, they will be composed into a single
  188. print rather than processed individually.
  189. Printer options:
  190. --nozzle-diameter Diameter of nozzle in mm (default: $config->{nozzle_diameter}->[0])
  191. --print-center Coordinates in mm of the point to center the print around
  192. (default: $config->{print_center}->[0],$config->{print_center}->[1])
  193. --z-offset Additional height in mm to add to vertical coordinates
  194. (+/-, default: $config->{z_offset})
  195. --gcode-flavor The type of G-code to generate (reprap/teacup/makerware/sailfish/mach3/no-extrusion,
  196. default: $config->{gcode_flavor})
  197. --use-relative-e-distances Enable this to get relative E values (default: no)
  198. --use-firmware-retraction Enable firmware-controlled retraction using G10/G11 (default: no)
  199. --gcode-arcs Use G2/G3 commands for native arcs (experimental, not supported
  200. by all firmwares)
  201. --g0 Use G0 commands for retraction (experimental, not supported by all
  202. firmwares)
  203. --gcode-comments Make G-code verbose by adding comments (default: no)
  204. --vibration-limit Limit the frequency of moves on X and Y axes (Hz, set zero to disable;
  205. default: $config->{vibration_limit})
  206. Filament options:
  207. --filament-diameter Diameter in mm of your raw filament (default: $config->{filament_diameter}->[0])
  208. --extrusion-multiplier
  209. Change this to alter the amount of plastic extruded. There should be
  210. very little need to change this value, which is only useful to
  211. compensate for filament packing (default: $config->{extrusion_multiplier}->[0])
  212. --temperature Extrusion temperature in degree Celsius, set 0 to disable (default: $config->{temperature}->[0])
  213. --first-layer-temperature Extrusion temperature for the first layer, in degree Celsius,
  214. set 0 to disable (default: same as --temperature)
  215. --bed-temperature Heated bed temperature in degree Celsius, set 0 to disable (default: $config->{bed_temperature})
  216. --first-layer-bed-temperature Heated bed temperature for the first layer, in degree Celsius,
  217. set 0 to disable (default: same as --bed-temperature)
  218. Speed options:
  219. --travel-speed Speed of non-print moves in mm/s (default: $config->{travel_speed})
  220. --perimeter-speed Speed of print moves for perimeters in mm/s (default: $config->{perimeter_speed})
  221. --small-perimeter-speed
  222. Speed of print moves for small perimeters in mm/s or % over perimeter speed
  223. (default: $config->{small_perimeter_speed})
  224. --external-perimeter-speed
  225. Speed of print moves for the external perimeter in mm/s or % over perimeter speed
  226. (default: $config->{external_perimeter_speed})
  227. --infill-speed Speed of print moves in mm/s (default: $config->{infill_speed})
  228. --solid-infill-speed Speed of print moves for solid surfaces in mm/s or % over infill speed
  229. (default: $config->{solid_infill_speed})
  230. --top-solid-infill-speed Speed of print moves for top surfaces in mm/s or % over solid infill speed
  231. (default: $config->{top_solid_infill_speed})
  232. --support-material-speed
  233. Speed of support material print moves in mm/s (default: $config->{support_material_speed})
  234. --bridge-speed Speed of bridge print moves in mm/s (default: $config->{bridge_speed})
  235. --gap-fill-speed Speed of gap fill print moves in mm/s (default: $config->{gap_fill_speed})
  236. --first-layer-speed Speed of print moves for bottom layer, expressed either as an absolute
  237. value or as a percentage over normal speeds (default: $config->{first_layer_speed})
  238. Acceleration options:
  239. --perimeter-acceleration
  240. Overrides firmware's default acceleration for perimeters. (mm/s^2, set zero
  241. to disable; default: $config->{perimeter_acceleration})
  242. --infill-acceleration
  243. Overrides firmware's default acceleration for infill. (mm/s^2, set zero
  244. to disable; default: $config->{infill_acceleration})
  245. --bridge-acceleration
  246. Overrides firmware's default acceleration for bridges. (mm/s^2, set zero
  247. to disable; default: $config->{bridge_acceleration})
  248. --first-layer-acceleration
  249. Overrides firmware's default acceleration for first layer. (mm/s^2, set zero
  250. to disable; default: $config->{first_layer_acceleration})
  251. --default-acceleration
  252. Acceleration will be reset to this value after the specific settings above
  253. have been applied. (mm/s^2, set zero to disable; default: $config->{travel_speed})
  254. Accuracy options:
  255. --layer-height Layer height in mm (default: $config->{layer_height})
  256. --first-layer-height Layer height for first layer (mm or %, default: $config->{first_layer_height})
  257. --infill-every-layers
  258. Infill every N layers (default: $config->{infill_every_layers})
  259. --solid-infill-every-layers
  260. Force a solid layer every N layers (default: $config->{solid_infill_every_layers})
  261. Print options:
  262. --perimeters Number of perimeters/horizontal skins (range: 0+, default: $config->{perimeters})
  263. --top-solid-layers Number of solid layers to do for top surfaces (range: 0+, default: $config->{top_solid_layers})
  264. --bottom-solid-layers Number of solid layers to do for bottom surfaces (range: 0+, default: $config->{bottom_solid_layers})
  265. --solid-layers Shortcut for setting the two options above at once
  266. --fill-density Infill density (range: 0-1, default: $config->{fill_density})
  267. --fill-angle Infill angle in degrees (range: 0-90, default: $config->{fill_angle})
  268. --fill-pattern Pattern to use to fill non-solid layers (default: $config->{fill_pattern})
  269. --solid-fill-pattern Pattern to use to fill solid layers (default: $config->{solid_fill_pattern})
  270. --start-gcode Load initial G-code from the supplied file. This will overwrite
  271. the default command (home all axes [G28]).
  272. --end-gcode Load final G-code from the supplied file. This will overwrite
  273. the default commands (turn off temperature [M104 S0],
  274. home X axis [G28 X], disable motors [M84]).
  275. --layer-gcode Load layer-change G-code from the supplied file (default: nothing).
  276. --toolchange-gcode Load tool-change G-code from the supplied file (default: nothing).
  277. --randomize-start Randomize starting point across layers (default: yes)
  278. --external-perimeters-first Reverse perimeter order. (default: no)
  279. --spiral-vase Experimental option to raise Z gradually when printing single-walled vases
  280. (default: no)
  281. --only-retract-when-crossing-perimeters
  282. Disable retraction when travelling between infill paths inside the same island.
  283. (default: no)
  284. --solid-infill-below-area
  285. Force solid infill when a region has a smaller area than this threshold
  286. (mm^2, default: $config->{solid_infill_below_area})
  287. --infill-only-where-needed
  288. Only infill under ceilings (default: no)
  289. --infill-first Make infill before perimeters (default: no)
  290. Quality options (slower slicing):
  291. --extra-perimeters Add more perimeters when needed (default: yes)
  292. --avoid-crossing-perimeters Optimize travel moves so that no perimeters are crossed (default: no)
  293. --start-perimeters-at-concave-points
  294. Try to start perimeters at concave points if any (default: no)
  295. --start-perimeters-at-non-overhang
  296. Try to start perimeters at non-overhang points if any (default: no)
  297. --thin-walls Detect single-width walls (default: yes)
  298. --overhangs Experimental option to use bridge flow, speed and fan for overhangs
  299. (default: yes)
  300. Support material options:
  301. --support-material Generate support material for overhangs
  302. --support-material-threshold
  303. Overhang threshold angle (range: 0-90, set 0 for automatic detection,
  304. default: $config->{support_material_threshold})
  305. --support-material-pattern
  306. Pattern to use for support material (default: $config->{support_material_pattern})
  307. --support-material-spacing
  308. Spacing between pattern lines (mm, default: $config->{support_material_spacing})
  309. --support-material-angle
  310. Support material angle in degrees (range: 0-90, default: $config->{support_material_angle})
  311. --support-material-interface-layers
  312. Number of perpendicular layers between support material and object (0+, default: $config->{support_material_interface_layers})
  313. --support-material-interface-spacing
  314. Spacing between interface pattern lines (mm, set 0 to get a solid layer, default: $config->{support_material_interface_spacing})
  315. --raft-layers Number of layers to raise the printed objects by (range: 0+, default: $config->{raft_layers})
  316. --support-material-enforce-layers
  317. Enforce support material on the specified number of layers from bottom,
  318. regardless of --support-material and threshold (0+, default: $config->{support_material_enforce_layers})
  319. Retraction options:
  320. --retract-length Length of retraction in mm when pausing extrusion (default: $config->{retract_length}[0])
  321. --retract-speed Speed for retraction in mm/s (default: $config->{retract_speed}[0])
  322. --retract-restart-extra
  323. Additional amount of filament in mm to push after
  324. compensating retraction (default: $config->{retract_restart_extra}[0])
  325. --retract-before-travel
  326. Only retract before travel moves of this length in mm (default: $config->{retract_before_travel}[0])
  327. --retract-lift Lift Z by the given distance in mm when retracting (default: $config->{retract_lift}[0])
  328. --retract-layer-change
  329. Enforce a retraction before each Z move (default: yes)
  330. --wipe Wipe the nozzle while doing a retraction (default: no)
  331. Retraction options for multi-extruder setups:
  332. --retract-length-toolchange
  333. Length of retraction in mm when disabling tool (default: $config->{retract_length}[0])
  334. --retract-restart-extra-toolchnage
  335. Additional amount of filament in mm to push after
  336. switching tool (default: $config->{retract_restart_extra}[0])
  337. Cooling options:
  338. --cooling Enable fan and cooling control
  339. --min-fan-speed Minimum fan speed (default: $config->{min_fan_speed}%)
  340. --max-fan-speed Maximum fan speed (default: $config->{max_fan_speed}%)
  341. --bridge-fan-speed Fan speed to use when bridging (default: $config->{bridge_fan_speed}%)
  342. --fan-below-layer-time Enable fan if layer print time is below this approximate number
  343. of seconds (default: $config->{fan_below_layer_time})
  344. --slowdown-below-layer-time Slow down if layer print time is below this approximate number
  345. of seconds (default: $config->{slowdown_below_layer_time})
  346. --min-print-speed Minimum print speed (mm/s, default: $config->{min_print_speed})
  347. --disable-fan-first-layers Disable fan for the first N layers (default: $config->{disable_fan_first_layers})
  348. --fan-always-on Keep fan always on at min fan speed, even for layers that don't need
  349. cooling
  350. Skirt options:
  351. --skirts Number of skirts to draw (0+, default: $config->{skirts})
  352. --skirt-distance Distance in mm between innermost skirt and object
  353. (default: $config->{skirt_distance})
  354. --skirt-height Height of skirts to draw (expressed in layers, 0+, default: $config->{skirt_height})
  355. --min-skirt-length Generate no less than the number of loops required to consume this length
  356. of filament on the first layer, for each extruder (mm, 0+, default: $config->{min_skirt_length})
  357. --brim-width Width of the brim that will get added to each object to help adhesion
  358. (mm, default: $config->{brim_width})
  359. Transform options:
  360. --scale Factor for scaling input object (default: 1)
  361. --rotate Rotation angle in degrees (0-360, default: 0)
  362. --duplicate Number of items with auto-arrange (1+, default: 1)
  363. --bed-size Bed size, only used for auto-arrange (mm, default: $config->{bed_size}->[0],$config->{bed_size}->[1])
  364. --duplicate-grid Number of items with grid arrangement (default: 1,1)
  365. --duplicate-distance Distance in mm between copies (default: $config->{duplicate_distance})
  366. Sequential printing options:
  367. --complete-objects When printing multiple objects and/or copies, complete each one before
  368. starting the next one; watch out for extruder collisions (default: no)
  369. --extruder-clearance-radius Radius in mm above which extruder won't collide with anything
  370. (default: $config->{extruder_clearance_radius})
  371. --extruder-clearance-height Maximum vertical extruder depth; i.e. vertical distance from
  372. extruder tip and carriage bottom (default: $config->{extruder_clearance_height})
  373. Miscellaneous options:
  374. --notes Notes to be added as comments to the output file
  375. --resolution Minimum detail resolution (mm, set zero for full resolution, default: $config->{resolution})
  376. Flow options (advanced):
  377. --extrusion-width Set extrusion width manually; it accepts either an absolute value in mm
  378. (like 0.65) or a percentage over layer height (like 200%)
  379. --first-layer-extrusion-width
  380. Set a different extrusion width for first layer
  381. --perimeter-extrusion-width
  382. Set a different extrusion width for perimeters
  383. --infill-extrusion-width
  384. Set a different extrusion width for infill
  385. --solid-infill-extrusion-width
  386. Set a different extrusion width for solid infill
  387. --top-infill-extrusion-width
  388. Set a different extrusion width for top infill
  389. --support-material-extrusion-width
  390. Set a different extrusion width for support material
  391. --bridge-flow-ratio Multiplier for extrusion when bridging (> 0, default: $config->{bridge_flow_ratio})
  392. Multiple extruder options:
  393. --extruder-offset Offset of each extruder, if firmware doesn't handle the displacement
  394. (can be specified multiple times, default: 0x0)
  395. --perimeter-extruder
  396. Extruder to use for perimeters (1+, default: $config->{perimeter_extruder})
  397. --infill-extruder Extruder to use for infill (1+, default: $config->{infill_extruder})
  398. --support-material-extruder
  399. Extruder to use for support material (1+, default: $config->{support_material_extruder})
  400. --support-material-interface-extruder
  401. Extruder to use for support material interface (1+, default: $config->{support_material_interface_extruder})
  402. --ooze-prevention Drop temperature and park extruders outside a full skirt for automatic wiping
  403. (default: no)
  404. --standby-temperature-delta
  405. Temperature difference to be applied when an extruder is not active and
  406. --ooze-prevention is enabled (default: $config->{standby_temperature_delta})
  407. EOF
  408. exit ($exit_code || 0);
  409. }
  410. __END__