amf-to-stl.pl 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. }
  9. use File::Basename qw(basename);
  10. use Getopt::Long qw(:config no_auto_abbrev);
  11. use Slic3r;
  12. $|++;
  13. my %opt = ();
  14. {
  15. my %options = (
  16. 'help' => sub { usage() },
  17. 'ascii' => \$opt{ascii},
  18. );
  19. GetOptions(%options) or usage(1);
  20. $ARGV[0] or usage(1);
  21. }
  22. {
  23. my $model = Slic3r::Model->load_amf(Slic3r::encode_path($ARGV[0]));
  24. my $output_file = $ARGV[0];
  25. $output_file =~ s/\.[aA][mM][fF](?:\.[xX][mM][lL])?$/\.stl/;
  26. printf "Writing to %s\n", basename($output_file);
  27. $model->store_stl(Slic3r::encode_path($output_file), binary => !$opt{ascii});
  28. }
  29. sub usage {
  30. my ($exit_code) = @_;
  31. print <<"EOF";
  32. Usage: amf-to-stl.pl [ OPTIONS ] file.amf
  33. --help Output this usage screen and exit
  34. --ascii Generate ASCII STL files (default: binary)
  35. EOF
  36. exit ($exit_code || 0);
  37. }
  38. __END__