Skip to content

Commit 267e176

Browse files
committed
Update for Inkscape 1.0.
- Adjust to changed export command line options of Inkscape. - Fix TypeError on Python 3. - Use the new file chooser support in the extension dialog. Making it an output extension instead of an effect to skip the unnecessary dialog is still not feasible because Inkscape still buffers the whole output in a continuously reallocated string instead of streaming it to disk.
1 parent 60f162c commit 267e176

File tree

3 files changed

+14
-23
lines changed

3 files changed

+14
-23
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
3-
<_name>3D-Printable Cookie Cutter</_name>
3+
<name>3D-Printable Cookie Cutter</name>
44
<id>ch.kolleegium.filter.cookiecutter</id>
55
<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>
6+
<param name="outputfile" type="path" mode="file_new" filetypes="stl" gui-text="Output STL File">~/cookie.stl</param>
77
<effect needs-live-preview="false">
88
<object-type>all</object-type>
99
<effects-menu>
10-
<submenu _name="Export"/>
10+
<submenu name="Export"/>
1111
</effects-menu>
1212
</effect>
1313
<script>
14-
<command reldir="extensions" interpreter="python">cookie-cutter-sweeper/export.py</command>
14+
<command location="inx" interpreter="python">export.py</command>
1515
</script>
1616
</inkscape-extension>

inkscape/cookie-cutter-sweeper/export.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,22 @@
4949
options, arguments = optionparser.parse_args()
5050

5151
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)
52+
process = subprocess.Popen(['inkscape', '--export-type=png', '--export-filename=' + 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)
5353
output = process.communicate()[0]
5454
if process.returncode != 0:
55-
sys.stderr.write('Calling inkscape failed:\n')
56-
sys.stderr.write(output)
55+
# Python 2+3 compatibility
56+
binstderr = sys.stderr.buffer if hasattr(sys.stderr, 'buffer') else sys.stderr
57+
binstderr.write(b'Calling inkscape failed:\n')
58+
binstderr.write(output)
5759
shutil.rmtree(tempdir, ignore_errors=True)
5860
sys.exit(process.returncode)
5961

6062
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)
6163
output = process.communicate()[1]
6264
if process.returncode != 0:
63-
sys.stderr.write('Calling sweep failed:\n')
64-
sys.stderr.write(output)
65+
binstderr = sys.stderr.buffer if hasattr(sys.stderr, 'buffer') else sys.stderr
66+
binstderr.write(b'Calling sweep failed:\n')
67+
binstderr.write(output)
6568
shutil.rmtree(tempdir, ignore_errors=True)
6669
sys.exit(process.returncode)
6770

inkscape/readme.txt

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,8 @@
11
Installing the Inkscape extension
22

3-
Place the file cookie-cutter-sweeper.inx and the folder cookie-cutter-sweeper in your Inkscape extensions folder
3+
Place the folder cookie-cutter-sweeper in your Inkscape extensions folder. To find where that is, open the Preferences dialog in Inkscape and use the "Open" button under "System > User Extensions". After restarting Inkscape, the extension appears under "Extensions > Export > 3D-Printable Cookie Cutter".
44

5-
On Mac OS X and Linux the extensions folder is at:
6-
7-
~/.config/inkscape/extensions
8-
9-
(on Mac OS X, use "Go > Go to Folder" in the Finder and paste this path to reveal the hidden folder)
10-
11-
On Windows it can be found at:
12-
13-
%APPDATA%\inkscape\extensions
14-
15-
(paste this path into the address line of an Explorer window).
16-
17-
After restarting Inkscape, the extension appears under "Extensions > Export > 3D-Printable Cookie Cutter".
5+
This version of the extension is compatible with Inkscape 1.0. It is not compatible with earlier versions.
186

197

208
Command line usage

0 commit comments

Comments
 (0)