Skip to content

Commit 6e69d70

Browse files
committed
Add Inkscape integration source code.
To build a functional extension, add the platform-specific binaries listed in .gitignore built from sweep.cpp.
1 parent 73aef0f commit 6e69d70

File tree

6 files changed

+106
-0
lines changed

6 files changed

+106
-0
lines changed

inkscape/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/cookie-cutter-sweeper/linux-i386/sweep
2+
/cookie-cutter-sweeper/linux-x86_64/sweep
3+
/cookie-cutter-sweeper/mac/sweep
4+
/cookie-cutter-sweeper/windows/sweep.exe

inkscape/cookie-cutter-sweeper.inx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
3+
<_name>3D-Printable Cookie Cutter</_name>
4+
<id>ch.kolleegium.filter.cookiecutter</id>
5+
<dependency type="executable" location="extensions">cookie-cutter-sweeper/export.py</dependency>
6+
<param name="outputfile" type="string" _gui-text="Output STL File">~/cookie.stl</param>
7+
<effect needs-live-preview="false">
8+
<object-type>all</object-type>
9+
<effects-menu>
10+
<submenu _name="Export"/>
11+
</effects-menu>
12+
</effect>
13+
<script>
14+
<command reldir="extensions" interpreter="python">cookie-cutter-sweeper/export.py</command>
15+
</script>
16+
</inkscape-extension>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env python
2+
3+
# Cookie Cutter Sweeper Inkscape Extension
4+
#
5+
# Copyright (c) 2015 Christian Walther
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in
15+
# all copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
# THE SOFTWARE.
24+
25+
import sys
26+
import os
27+
import subprocess
28+
import tempfile
29+
import shutil
30+
import platform
31+
import optparse
32+
33+
if __name__ == '__main__':
34+
if sys.platform.startswith('darwin'):
35+
bindir = 'mac'
36+
elif sys.platform.startswith('win32'):
37+
bindir = 'windows'
38+
elif sys.platform.startswith('linux') and platform.machine() == 'x86_64':
39+
bindir = 'linux-x86_64'
40+
elif sys.platform.startswith('linux') and platform.machine() == 'i686':
41+
bindir = 'linux-i386'
42+
else:
43+
sys.stderr.write('Your platform "' + sys.platform + ' ' + platform.machine() + '" is not currently supported by the Cookie Cutter Sweeper integration. Try building Cookie Cutter Sweeper from source (https://github.com/cwalther/cookie-cutter-sweeper) and adjusting the Inkscape extension in ' + os.path.join(os.getcwd(), __file__) + '.')
44+
sys.exit(1)
45+
46+
optionparser = optparse.OptionParser(usage='usage: %prog [options] SVGfile')
47+
optionparser.add_option('--id', action='append', type='string', dest='ids', default=[], help='id attribute of selected object, ignored')
48+
optionparser.add_option('-o', '--outputfile', action='store', type='string', dest='outputfile', default='~/cookie.stl', help='STL output file')
49+
options, arguments = optionparser.parse_args()
50+
51+
tempdir = tempfile.mkdtemp()
52+
process = subprocess.Popen(['inkscape', '--export-png=' + os.path.join(tempdir, 'cookie.png'), '--export-area-drawing', '--export-dpi=254', '--export-background=#000000', '--export-background-opacity=0', arguments[-1]], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
53+
output = process.communicate()[0]
54+
if process.returncode != 0:
55+
sys.stderr.write('Calling inkscape failed:\n')
56+
sys.stderr.write(output)
57+
shutil.rmtree(tempdir, ignore_errors=True)
58+
sys.exit(process.returncode)
59+
60+
process = subprocess.Popen([os.path.join(os.getcwd(), bindir, 'sweep'), '--flip-x', os.path.join(os.getcwd(), 'section.png'), os.path.join(tempdir, 'cookie.png'), os.path.expanduser(options.outputfile)], stderr=subprocess.PIPE)
61+
output = process.communicate()[1]
62+
if process.returncode != 0:
63+
sys.stderr.write('Calling sweep failed:\n')
64+
sys.stderr.write(output)
65+
shutil.rmtree(tempdir, ignore_errors=True)
66+
sys.exit(process.returncode)
67+
68+
shutil.rmtree(tempdir, ignore_errors=True)
648 Bytes
Loading
801 Bytes
Loading

inkscape/readme.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Installing the Inkscape extension
2+
3+
Place the file cookie-cutter-sweeper.inx and the folder cookie-cutter-sweeper in your Inkscape extensions folder, which can be found at
4+
5+
~/.config/inkscape/extensions
6+
7+
on Mac OS X and Linux (on Mac OS X, use "Go > Go to Folder" in the Finder and paste this) and at
8+
9+
%APPDATA%\inkscape\extensions
10+
11+
on Windows (paste this into the address line of an Explorer window).
12+
13+
After restarting Inkscape, the extension appears under "Extensions > Export > 3D-Printable Cookie Cutter".
14+
15+
16+
Command line usage
17+
18+
For more options, find the "sweep" binary for your platform in the subfolders of cookie-cutter-sweeper and run it on the command line. Running without arguments outputs a usage description.

0 commit comments

Comments
 (0)