forked from samyk/samytools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautodxf2svg
executable file
·64 lines (55 loc) · 1.15 KB
/
autodxf2svg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/perl
#
# automatically convert .dxf's to .svg's (typically Fusion 360 DXFs to SVGs for use in Glowforge)
# requires "dxf2svg" at https://github.com/samyk/samytools
# -samy kamkar 2018/05/17
#
my $dxf2svg = "dxf2svg"; # tool to convert dxfs to svg (this runs inkscape)
my $DEFAULT_DIR = "$ENV{HOME}/Code/3D";
use strict;
if ($ARGV[0] eq "-h" || @ARGV > 1)
{
die "usage: $0 [-h] [dir to watch for dxf]\n";
}
my $dir = shift || $DEFAULT_DIR;
if (my $p = fork)
{
die "Running in bg! (pid $p)\n";
}
close(STDERR);
close(STDIN);
close(STDOUT);
my %files = map { $_ => mtime($_) } <$dir/*.dxf>;
use Data::Dumper;
#print Dumper(\%files);
while (1)
{
foreach my $file (<$dir/*.dxf>)
{
my $mtime = mtime($file);
# new file or newer mod time
if (!$files{$file})
{
#print "New file: $file\n";
$files{$file} = $mtime;
dxf2svg($file);
}
elsif ($mtime > $files{$file})
{
#print "Newer mod time: $file\n";
$files{$file} = $mtime;
dxf2svg($file);
}
}
sleep 1;
}
sub mtime
{
return (stat($_[0]))[9];
}
sub dxf2svg
{
my $out = $_[0];
$out =~ s/dxf$/svg/;
system($dxf2svg, $_[0], $out);
}