amf-to-stl.pl 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. my %opt = ();
  15. {
  16. my %options = (
  17. 'help' => sub { usage() },
  18. 'ascii' => \$opt{ascii},
  19. );
  20. GetOptions(%options) or usage(1);
  21. $ARGV[0] or usage(1);
  22. }
  23. {
  24. my $model = Slic3r::Model->read_from_file($ARGV[0]);
  25. my $output_file = $ARGV[0];
  26. $output_file =~ s/\.amf(?:\.xml)?$/\.stl/i;
  27. printf "Writing to %s\n", basename($output_file);
  28. $model->write_stl($output_file, !$opt{ascii});
  29. }
  30. sub usage {
  31. my ($exit_code) = @_;
  32. print <<"EOF";
  33. Usage: amf-to-stl.pl [ OPTIONS ] file.amf
  34. --help Output this usage screen and exit
  35. --ascii Generate ASCII STL files (default: binary)
  36. EOF
  37. exit ($exit_code || 0);
  38. }
  39. __END__