slic3r.pl 21 KB

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