amf-to-stl.pl 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/perl
  2. # This script converts an AMF file to STL
  3. use strict;
  4. use warnings;
  5. BEGIN {
  6. use FindBin;
  7. use lib "$FindBin::Bin/../lib";
  8. use local::lib "$FindBin::Bin/../local-lib";
  9. }
  10. use File::Basename qw(basename);
  11. use Getopt::Long qw(:config no_auto_abbrev);
  12. use Slic3r;
  13. $|++;
  14. # Convert all parameters from the local code page to utf8 on Windows.
  15. @ARGV = map Slic3r::decode_path($_), @ARGV if $^O eq 'MSWin32';
  16. my %opt = ();
  17. {
  18. my %options = (
  19. 'help' => sub { usage() },
  20. 'ascii' => \$opt{ascii},
  21. );
  22. GetOptions(%options) or usage(1);
  23. $ARGV[0] or usage(1);
  24. }
  25. {
  26. my $model = Slic3r::Model->load_amf($ARGV[0]);
  27. my $output_file = $ARGV[0];
  28. $output_file =~ s/\.[aA][mM][fF](?:\.[xX][mM][lL])?$/\.stl/;
  29. printf "Writing to %s\n", basename($output_file);
  30. $model->store_stl($output_file, binary => !$opt{ascii});
  31. }
  32. sub usage {
  33. my ($exit_code) = @_;
  34. print <<"EOF";
  35. Usage: amf-to-stl.pl [ OPTIONS ] file.amf
  36. --help Output this usage screen and exit
  37. --ascii Generate ASCII STL files (default: binary)
  38. EOF
  39. exit ($exit_code || 0);
  40. }
  41. __END__