Skip to content

Instantly share code, notes, and snippets.

@ppelleti
Created May 4, 2016 02:22
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ppelleti/eba27c66b3a20d89ca4e1e30c05e81c1 to your computer and use it in GitHub Desktop.
Save ppelleti/eba27c66b3a20d89ca4e1e30c05e81c1 to your computer and use it in GitHub Desktop.
Convert SVG files to DXF files on Mac OS X
#!/usr/bin/perl -w
# svg-to-dxf.pl - convert SVG files to DXF files on Mac OS X
# by Patrick Pelletier, public domain (or cc0)
# based on the commands suggested here:
# https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Other_2D_formats
# assumes Inkscape.app is installed in /Applications
# and pstoedit is installed in PATH, such as via "brew install pstoedit"
use Cwd qw(abs_path);
use File::Temp ();
die "Usage: $0 filename.svg\n" if ($#ARGV != 0); # 0 means 1 argument
my ($src) = @ARGV;
$src = abs_path($src); # because inkscape changes current directory
my $dest = $src;
$dest =~ s/\.svg$/.dxf/;
die "filename doesn't end in .svg" if ($src eq $dest);
my $intermediate = File::Temp->new(SUFFIX => '.eps');
system ("/Applications/Inkscape.app/Contents/Resources/bin/inkscape", "-E",
$intermediate, $src) == 0 or die "inkscape failed";
system ("pstoedit", "-q", "-dt", "-f", "dxf:-polyaslines -mm",
$intermediate, $dest) == 0 or die "pstoedit failed";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment