slic3r.pl 15 KB

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