diff options
| author | Aaron Spike <aaron@ekips.org> | 2006-01-29 15:03:14 +0000 |
|---|---|---|
| committer | acspike <acspike@users.sourceforge.net> | 2006-01-29 15:03:14 +0000 |
| commit | 99ee2c31cd74d1f44265138358069791c3f750ce (patch) | |
| tree | a0b1c63a8614d92f147a59820a42142ba1f57e92 | |
| parent | use namedview->snap_* variables instead of namedview->*_snapper, (diff) | |
| download | inkscape-99ee2c31cd74d1f44265138358069791c3f750ce.tar.gz inkscape-99ee2c31cd74d1f44265138358069791c3f750ce.zip | |
Adding minimal dxf output as a python extension. Converts path segments to splines and lines.
(bzr r46)
| -rw-r--r-- | share/extensions/Makefile.am | 6 | ||||
| -rw-r--r-- | share/extensions/dxf_outlines.inx | 18 | ||||
| -rwxr-xr-x | share/extensions/dxf_outlines.py | 62 |
3 files changed, 84 insertions, 2 deletions
diff --git a/share/extensions/Makefile.am b/share/extensions/Makefile.am index 2e32312ca..67d86bca8 100644 --- a/share/extensions/Makefile.am +++ b/share/extensions/Makefile.am @@ -44,7 +44,8 @@ extensions = \ ps2dxf.sh \ embedimage.py \ extractimage.py \ - svg_and_media_zip_output.py + svg_and_media_zip_output.py \ + dxf_outlines.py otherstuff = @@ -84,7 +85,8 @@ modules = \ dxf_input.inx \ embedimage.inx \ extractimage.inx \ - svg_and_media_zip_output.inx + svg_and_media_zip_output.inx \ + dxf_outlines.py extension_SCRIPTS = \ $(extensions) diff --git a/share/extensions/dxf_outlines.inx b/share/extensions/dxf_outlines.inx new file mode 100644 index 000000000..cc8d1a15b --- /dev/null +++ b/share/extensions/dxf_outlines.inx @@ -0,0 +1,18 @@ +<inkscape-extension> + <_name>Dxf Outlines</_name> + <id>org.ekips.output.dxf_outlines</id> + <dependency type="extension">org.inkscape.output.svg.inkscape</dependency> + <dependency type="executable" location="extensions">dxf_outlines.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <output> + <extension>.dxf</extension> + <mimetype>application/x-dxf</mimetype> + <_filetypename>Path outlines converted to DXF splines (*.DXF)</_filetypename> + <_filetypetooltip>Path outlines converted to DXF splines</_filetypetooltip> + <dataloss>TRUE</dataloss> + </output> + <script> + <command reldir="extensions" interpreter="python">dxf_outlines.py</command> + <helper_extension>org.inkscape.output.svg.inkscape</helper_extension> + </script> +</inkscape-extension> diff --git a/share/extensions/dxf_outlines.py b/share/extensions/dxf_outlines.py new file mode 100755 index 000000000..c73d0dad0 --- /dev/null +++ b/share/extensions/dxf_outlines.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python +''' +Copyright (C) 2005 Aaron Spike, aaron@ekips.org + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +''' +import inkex, cubicsuperpath + +class MyEffect(inkex.Effect): + def __init__(self): + inkex.Effect.__init__(self) + self.dxf = '' + def output(self): + print self.dxf + def dxf_add(self, str): + self.dxf += str + def dxf_line(self,csp): + line = "\n0\nLINE\n8\n2\n62\n4\n10\n%f\n20\n%f\n30\n0\n11\n%f\n21\n%f\n31\n0" % (csp[0][0],csp[0][1],csp[1][0],csp[1][1]) + self.dxf_add(line) + def dxf_spline(self,csp): + knots = 8 + ctrls = 4 + self.dxf_add("\n 0\nSPLINE\n 5\n43\n 8\n0\n 62\n256\n370\n-1\n 6\nByLayer") + self.dxf_add("\n100\nAcDbEntity\n100\nAcDbSpline\n 70\n8\n 71\n3\n 72\n%d\n 73\n%d\n 74\n0" % (knots, ctrls)) + for i in range(2): + for j in range(4): + self.dxf_add("\n 40\n%d" % i) + for i in csp: + self.dxf_add("\n 10\n%f\n 20\n%f\n 30\n0" % (i[0],i[1])) + def effect(self): + #References: Minimum Requirements for Creating a DXF File of a 3D Model By Paul Bourke + # NURB Curves: A Guide for the Uninitiated By Philip J. Schneider + self.dxf_add("999\nDXF created by Inkscape\n0\nSECTION\n2\nENTITIES") + + path = '//path' + for node in inkex.xml.xpath.Evaluate(path,self.document): + p = cubicsuperpath.parsePath(node.attributes.getNamedItem('d').value) + for sub in p: + for i in range(len(sub)-1): + s = sub[i] + e = sub[i+1] + if s[1] == s[2] and e[0] == e[1]: + self.dxf_line([s[1],e[1]]) + else: + self.dxf_spline([s[1],s[2],e[0],e[1]]) + self.dxf_add("\n0\nENDSEC\n0\nEOF\n") + + +e = MyEffect() +e.affect() |
