8
use lib "$FindBin::Bin/lib";
11
use Getopt::Long qw(:config no_auto_abbrev);
12
use List::Util qw(first);
13
use POSIX qw(setlocale LC_NUMERIC);
15
use Time::HiRes qw(gettimeofday tv_interval);
22
'help' => sub { usage() },
23
'version' => sub { print "$Slic3r::VERSION\n"; exit 0 },
25
'debug' => \$Slic3r::debug,
27
'o|output=s' => \$opt{output},
29
'save=s' => \$opt{save},
30
'load=s@' => \$opt{load},
31
'autosave=s' => \$opt{autosave},
32
'ignore-nonexistent-config' => \$opt{ignore_nonexistent_config},
33
'no-plater' => \$opt{no_plater},
34
'gui-mode=s' => \$opt{gui_mode},
35
'datadir=s' => \$opt{datadir},
36
'export-svg' => \$opt{export_svg},
37
'merge|m' => \$opt{merge},
38
'repair' => \$opt{repair},
39
'cut=f' => \$opt{cut},
40
'info' => \$opt{info},
42
'scale=f' => \$opt{scale},
43
'rotate=i' => \$opt{rotate},
44
'duplicate=i' => \$opt{duplicate},
45
'duplicate-grid=s' => \$opt{duplicate_grid},
47
foreach my $opt_key (keys %{$Slic3r::Config::Options}) {
48
my $cli = $Slic3r::Config::Options->{$opt_key}->{cli} or next;
49
# allow both the dash-separated option name and the full opt_key
50
$options{ "$opt_key|$cli" } = \$cli_options{$opt_key};
53
GetOptions(%options) or usage(1);
56
# load configuration files
57
my @external_configs = ();
59
foreach my $configfile (@{$opt{load}}) {
61
push @external_configs, Slic3r::Config->load($configfile);
62
} elsif (-e "$FindBin::Bin/$configfile") {
63
printf STDERR "Loading $FindBin::Bin/$configfile\n";
64
push @external_configs, Slic3r::Config->load("$FindBin::Bin/$configfile");
66
$opt{ignore_nonexistent_config} or die "Cannot find specified configuration file ($configfile).\n";
71
# process command line options
72
my $cli_config = Slic3r::Config->new;
73
foreach my $c (@external_configs, Slic3r::Config->new_from_cli(%cli_options)) {
74
$c->normalize; # expand shortcuts before applying, otherwise destination values would be already filled with defaults
75
$cli_config->apply($c);
80
$cli_config->save($opt{save});
83
# apply command line config on top of default config
84
my $config = Slic3r::Config->new_from_defaults;
85
$config->apply($cli_config);
89
if (!@ARGV && !$opt{save} && eval "require Slic3r::GUI; 1") {
92
$Slic3r::GUI::datadir = $opt{datadir};
93
$Slic3r::GUI::no_plater = $opt{no_plater};
94
$Slic3r::GUI::mode = $opt{gui_mode};
95
$Slic3r::GUI::autosave = $opt{autosave};
97
$gui = Slic3r::GUI->new;
98
setlocale(LC_NUMERIC, 'C');
99
$gui->{skeinpanel}->load_config_file($_) for @{$opt{load}};
100
$gui->{skeinpanel}->load_config($cli_config);
104
die $@ if $@ && $opt{gui};
106
if (@ARGV) { # slicing from command line
110
foreach my $file (@ARGV) {
111
die "Repair is currently supported only on STL files\n"
112
if $file !~ /\.stl$/i;
114
my $output_file = $file;
115
$output_file =~ s/\.(stl)$/_fixed.obj/i;
116
my $tmesh = Slic3r::TriangleMesh->new;
117
$tmesh->ReadSTLFile($file);
119
$tmesh->WriteOBJFile($output_file);
125
foreach my $file (@ARGV) {
126
my $model = Slic3r::Model->read_from_file($file);
127
$model->add_default_instances;
128
my $mesh = $model->mesh;
129
$mesh->translate(0, 0, -$mesh->bounding_box->z_min);
130
my $upper = Slic3r::TriangleMesh->new;
131
my $lower = Slic3r::TriangleMesh->new;
132
$mesh->cut($opt{cut}, $upper, $lower);
135
$upper->write_ascii("${file}_upper.stl")
136
if $upper->facets_count > 0;
137
$lower->write_ascii("${file}_lower.stl")
138
if $lower->facets_count > 0;
143
while (my $input_file = shift @ARGV) {
146
my @models = map Slic3r::Model->read_from_file($_), $input_file, (splice @ARGV, 0);
147
$model = Slic3r::Model->merge(@models);
149
$model = Slic3r::Model->read_from_file($input_file);
157
if (defined $opt{duplicate_grid}) {
158
$opt{duplicate_grid} = [ split /[,x]/, $opt{duplicate_grid}, 2 ];
161
my $sprint = Slic3r::Print::Simple->new(
162
scale => $opt{scale} // 1,
163
rotate => $opt{rotate} // 0,
164
duplicate => $opt{duplicate} // 1,
165
duplicate_grid => $opt{duplicate_grid} // [1,1],
167
my ($percent, $message) = @_;
168
printf "=> %s\n", $message;
170
output_file => $opt{output},
173
$sprint->apply_config($config);
174
$sprint->set_model($model);
176
if ($opt{export_svg}) {
179
my $t0 = [gettimeofday];
180
$sprint->export_gcode;
182
# output some statistics
184
my $duration = tv_interval($t0);
185
printf "Done. Process took %d minutes and %.3f seconds\n",
186
int($duration/60), ($duration - int($duration/60)*60); # % truncates to integer
188
printf "Filament required: %.1fmm (%.1fcm3)\n",
189
$sprint->total_used_filament, $sprint->total_extruded_volume/1000;
193
usage(1) unless $opt{save};
197
my ($exit_code) = @_;
199
my $config = Slic3r::Config->new_from_defaults->as_hash;
202
if ($Slic3r::have_threads) {
204
-j, --threads <num> Number of threads to use (1+, default: $config->{threads})
209
Slic3r $Slic3r::VERSION is a STL-to-GCODE translator for RepRap 3D printers
210
written by Alessandro Ranellucci <aar\@cpan.org> - http://slic3r.org/
212
Usage: slic3r.pl [ OPTIONS ] [ file.stl ] [ file2.stl ] ...
214
--help Output this usage screen and exit
215
--version Output the version of Slic3r and exit
216
--save <file> Save configuration to the specified file
217
--load <file> Load configuration from the specified file. It can be used
218
more than once to load options from multiple files.
219
-o, --output <file> File to output gcode to (by default, the file will be saved
220
into the same directory as the input file using the
221
--output-filename-format to generate the filename.) If a
222
directory is specified for this option, the output will
223
be saved under that directory, and the filename will be
224
generated by --output-filename-format.
226
Non-slicing actions (no G-code will be generated):
227
--repair Repair given STL files and save them as <name>_fixed.obj
228
--cut <z> Cut given input files at given Z (relative) and export
229
them as <name>_upper.stl and <name>_lower.stl
230
--info Output information about the supplied file(s) and exit
234
--no-plater Disable the plater tab
235
--gui-mode Overrides the configured mode (simple/expert)
236
--autosave <file> Automatically export current configuration to the specified file
239
--output-filename-format
240
Output file name format; all config options enclosed in brackets
241
will be replaced by their values, as well as [input_filename_base]
242
and [input_filename] (default: $config->{output_filename_format})
243
--post-process Generated G-code will be processed with the supplied script;
244
call this more than once to process through multiple scripts.
245
--export-svg Export a SVG file containing slices instead of G-code.
246
-m, --merge If multiple files are supplied, they will be composed into a single
247
print rather than processed individually.
250
--nozzle-diameter Diameter of nozzle in mm (default: $config->{nozzle_diameter}->[0])
251
--print-center Coordinates in mm of the point to center the print around
252
(default: $config->{print_center}->[0],$config->{print_center}->[1])
253
--z-offset Additional height in mm to add to vertical coordinates
254
(+/-, default: $config->{z_offset})
255
--gcode-flavor The type of G-code to generate (reprap/teacup/makerware/sailfish/mach3/no-extrusion,
256
default: $config->{gcode_flavor})
257
--use-relative-e-distances Enable this to get relative E values (default: no)
258
--use-firmware-retraction Enable firmware-controlled retraction using G10/G11 (default: no)
259
--gcode-arcs Use G2/G3 commands for native arcs (experimental, not supported
261
--g0 Use G0 commands for retraction (experimental, not supported by all
263
--gcode-comments Make G-code verbose by adding comments (default: no)
264
--vibration-limit Limit the frequency of moves on X and Y axes (Hz, set zero to disable;
265
default: $config->{vibration_limit})
268
--filament-diameter Diameter in mm of your raw filament (default: $config->{filament_diameter}->[0])
269
--extrusion-multiplier
270
Change this to alter the amount of plastic extruded. There should be
271
very little need to change this value, which is only useful to
272
compensate for filament packing (default: $config->{extrusion_multiplier}->[0])
273
--temperature Extrusion temperature in degree Celsius, set 0 to disable (default: $config->{temperature}->[0])
274
--first-layer-temperature Extrusion temperature for the first layer, in degree Celsius,
275
set 0 to disable (default: same as --temperature)
276
--bed-temperature Heated bed temperature in degree Celsius, set 0 to disable (default: $config->{bed_temperature})
277
--first-layer-bed-temperature Heated bed temperature for the first layer, in degree Celsius,
278
set 0 to disable (default: same as --bed-temperature)
281
--travel-speed Speed of non-print moves in mm/s (default: $config->{travel_speed})
282
--perimeter-speed Speed of print moves for perimeters in mm/s (default: $config->{perimeter_speed})
283
--small-perimeter-speed
284
Speed of print moves for small perimeters in mm/s or % over perimeter speed
285
(default: $config->{small_perimeter_speed})
286
--external-perimeter-speed
287
Speed of print moves for the external perimeter in mm/s or % over perimeter speed
288
(default: $config->{external_perimeter_speed})
289
--infill-speed Speed of print moves in mm/s (default: $config->{infill_speed})
290
--solid-infill-speed Speed of print moves for solid surfaces in mm/s or % over infill speed
291
(default: $config->{solid_infill_speed})
292
--top-solid-infill-speed Speed of print moves for top surfaces in mm/s or % over solid infill speed
293
(default: $config->{top_solid_infill_speed})
294
--support-material-speed
295
Speed of support material print moves in mm/s (default: $config->{support_material_speed})
296
--support-material-interface-speed
297
Speed of support material interface print moves in mm/s or % over support material
298
speed (default: $config->{support_material_interface_speed})
299
--bridge-speed Speed of bridge print moves in mm/s (default: $config->{bridge_speed})
300
--gap-fill-speed Speed of gap fill print moves in mm/s (default: $config->{gap_fill_speed})
301
--first-layer-speed Speed of print moves for bottom layer, expressed either as an absolute
302
value or as a percentage over normal speeds (default: $config->{first_layer_speed})
304
Acceleration options:
305
--perimeter-acceleration
306
Overrides firmware's default acceleration for perimeters. (mm/s^2, set zero
307
to disable; default: $config->{perimeter_acceleration})
308
--infill-acceleration
309
Overrides firmware's default acceleration for infill. (mm/s^2, set zero
310
to disable; default: $config->{infill_acceleration})
311
--bridge-acceleration
312
Overrides firmware's default acceleration for bridges. (mm/s^2, set zero
313
to disable; default: $config->{bridge_acceleration})
314
--first-layer-acceleration
315
Overrides firmware's default acceleration for first layer. (mm/s^2, set zero
316
to disable; default: $config->{first_layer_acceleration})
317
--default-acceleration
318
Acceleration will be reset to this value after the specific settings above
319
have been applied. (mm/s^2, set zero to disable; default: $config->{travel_speed})
322
--layer-height Layer height in mm (default: $config->{layer_height})
323
--first-layer-height Layer height for first layer (mm or %, default: $config->{first_layer_height})
324
--infill-every-layers
325
Infill every N layers (default: $config->{infill_every_layers})
326
--solid-infill-every-layers
327
Force a solid layer every N layers (default: $config->{solid_infill_every_layers})
330
--perimeters Number of perimeters/horizontal skins (range: 0+, default: $config->{perimeters})
331
--top-solid-layers Number of solid layers to do for top surfaces (range: 0+, default: $config->{top_solid_layers})
332
--bottom-solid-layers Number of solid layers to do for bottom surfaces (range: 0+, default: $config->{bottom_solid_layers})
333
--solid-layers Shortcut for setting the two options above at once
334
--fill-density Infill density (range: 0%-100%, default: $config->{fill_density}%)
335
--fill-angle Infill angle in degrees (range: 0-90, default: $config->{fill_angle})
336
--fill-pattern Pattern to use to fill non-solid layers (default: $config->{fill_pattern})
337
--solid-fill-pattern Pattern to use to fill solid layers (default: $config->{solid_fill_pattern})
338
--start-gcode Load initial G-code from the supplied file. This will overwrite
339
the default command (home all axes [G28]).
340
--end-gcode Load final G-code from the supplied file. This will overwrite
341
the default commands (turn off temperature [M104 S0],
342
home X axis [G28 X], disable motors [M84]).
343
--layer-gcode Load layer-change G-code from the supplied file (default: nothing).
344
--toolchange-gcode Load tool-change G-code from the supplied file (default: nothing).
345
--seam-position Position of loop starting points (random/nearest/aligned, default: $config->{seam_position}).
346
--external-perimeters-first Reverse perimeter order. (default: no)
347
--spiral-vase Experimental option to raise Z gradually when printing single-walled vases
349
--only-retract-when-crossing-perimeters
350
Disable retraction when travelling between infill paths inside the same island.
352
--solid-infill-below-area
353
Force solid infill when a region has a smaller area than this threshold
354
(mm^2, default: $config->{solid_infill_below_area})
355
--infill-only-where-needed
356
Only infill under ceilings (default: no)
357
--infill-first Make infill before perimeters (default: no)
359
Quality options (slower slicing):
360
--extra-perimeters Add more perimeters when needed (default: yes)
361
--avoid-crossing-perimeters Optimize travel moves so that no perimeters are crossed (default: no)
362
--thin-walls Detect single-width walls (default: yes)
363
--overhangs Experimental option to use bridge flow, speed and fan for overhangs
366
Support material options:
367
--support-material Generate support material for overhangs
368
--support-material-threshold
369
Overhang threshold angle (range: 0-90, set 0 for automatic detection,
370
default: $config->{support_material_threshold})
371
--support-material-pattern
372
Pattern to use for support material (default: $config->{support_material_pattern})
373
--support-material-spacing
374
Spacing between pattern lines (mm, default: $config->{support_material_spacing})
375
--support-material-angle
376
Support material angle in degrees (range: 0-90, default: $config->{support_material_angle})
377
--support-material-interface-layers
378
Number of perpendicular layers between support material and object (0+, default: $config->{support_material_interface_layers})
379
--support-material-interface-spacing
380
Spacing between interface pattern lines (mm, set 0 to get a solid layer, default: $config->{support_material_interface_spacing})
381
--raft-layers Number of layers to raise the printed objects by (range: 0+, default: $config->{raft_layers})
382
--support-material-enforce-layers
383
Enforce support material on the specified number of layers from bottom,
384
regardless of --support-material and threshold (0+, default: $config->{support_material_enforce_layers})
385
--dont-support-bridges
386
Experimental option for preventing support material from being generated under bridged areas (default: yes)
389
--retract-length Length of retraction in mm when pausing extrusion (default: $config->{retract_length}[0])
390
--retract-speed Speed for retraction in mm/s (default: $config->{retract_speed}[0])
391
--retract-restart-extra
392
Additional amount of filament in mm to push after
393
compensating retraction (default: $config->{retract_restart_extra}[0])
394
--retract-before-travel
395
Only retract before travel moves of this length in mm (default: $config->{retract_before_travel}[0])
396
--retract-lift Lift Z by the given distance in mm when retracting (default: $config->{retract_lift}[0])
397
--retract-layer-change
398
Enforce a retraction before each Z move (default: yes)
399
--wipe Wipe the nozzle while doing a retraction (default: no)
401
Retraction options for multi-extruder setups:
402
--retract-length-toolchange
403
Length of retraction in mm when disabling tool (default: $config->{retract_length}[0])
404
--retract-restart-extra-toolchnage
405
Additional amount of filament in mm to push after
406
switching tool (default: $config->{retract_restart_extra}[0])
409
--cooling Enable fan and cooling control
410
--min-fan-speed Minimum fan speed (default: $config->{min_fan_speed}%)
411
--max-fan-speed Maximum fan speed (default: $config->{max_fan_speed}%)
412
--bridge-fan-speed Fan speed to use when bridging (default: $config->{bridge_fan_speed}%)
413
--fan-below-layer-time Enable fan if layer print time is below this approximate number
414
of seconds (default: $config->{fan_below_layer_time})
415
--slowdown-below-layer-time Slow down if layer print time is below this approximate number
416
of seconds (default: $config->{slowdown_below_layer_time})
417
--min-print-speed Minimum print speed (mm/s, default: $config->{min_print_speed})
418
--disable-fan-first-layers Disable fan for the first N layers (default: $config->{disable_fan_first_layers})
419
--fan-always-on Keep fan always on at min fan speed, even for layers that don't need
423
--skirts Number of skirts to draw (0+, default: $config->{skirts})
424
--skirt-distance Distance in mm between innermost skirt and object
425
(default: $config->{skirt_distance})
426
--skirt-height Height of skirts to draw (expressed in layers, 0+, default: $config->{skirt_height})
427
--min-skirt-length Generate no less than the number of loops required to consume this length
428
of filament on the first layer, for each extruder (mm, 0+, default: $config->{min_skirt_length})
429
--brim-width Width of the brim that will get added to each object to help adhesion
430
(mm, default: $config->{brim_width})
433
--scale Factor for scaling input object (default: 1)
434
--rotate Rotation angle in degrees (0-360, default: 0)
435
--duplicate Number of items with auto-arrange (1+, default: 1)
436
--bed-size Bed size, only used for auto-arrange (mm, default: $config->{bed_size}->[0],$config->{bed_size}->[1])
437
--duplicate-grid Number of items with grid arrangement (default: 1,1)
438
--duplicate-distance Distance in mm between copies (default: $config->{duplicate_distance})
440
Sequential printing options:
441
--complete-objects When printing multiple objects and/or copies, complete each one before
442
starting the next one; watch out for extruder collisions (default: no)
443
--extruder-clearance-radius Radius in mm above which extruder won't collide with anything
444
(default: $config->{extruder_clearance_radius})
445
--extruder-clearance-height Maximum vertical extruder depth; i.e. vertical distance from
446
extruder tip and carriage bottom (default: $config->{extruder_clearance_height})
448
Miscellaneous options:
449
--notes Notes to be added as comments to the output file
450
--resolution Minimum detail resolution (mm, set zero for full resolution, default: $config->{resolution})
452
Flow options (advanced):
453
--extrusion-width Set extrusion width manually; it accepts either an absolute value in mm
454
(like 0.65) or a percentage over layer height (like 200%)
455
--first-layer-extrusion-width
456
Set a different extrusion width for first layer
457
--perimeter-extrusion-width
458
Set a different extrusion width for perimeters
459
--infill-extrusion-width
460
Set a different extrusion width for infill
461
--solid-infill-extrusion-width
462
Set a different extrusion width for solid infill
463
--top-infill-extrusion-width
464
Set a different extrusion width for top infill
465
--support-material-extrusion-width
466
Set a different extrusion width for support material
467
--bridge-flow-ratio Multiplier for extrusion when bridging (> 0, default: $config->{bridge_flow_ratio})
469
Multiple extruder options:
470
--extruder-offset Offset of each extruder, if firmware doesn't handle the displacement
471
(can be specified multiple times, default: 0x0)
473
Extruder to use for perimeters (1+, default: $config->{perimeter_extruder})
474
--infill-extruder Extruder to use for infill (1+, default: $config->{infill_extruder})
475
--support-material-extruder
476
Extruder to use for support material (1+, default: $config->{support_material_extruder})
477
--support-material-interface-extruder
478
Extruder to use for support material interface (1+, default: $config->{support_material_interface_extruder})
479
--ooze-prevention Drop temperature and park extruders outside a full skirt for automatic wiping
481
--standby-temperature-delta
482
Temperature difference to be applied when an extruder is not active and
483
--ooze-prevention is enabled (default: $config->{standby_temperature_delta})
486
exit ($exit_code || 0);