martymcguire / inkscape-openscad-poly Goto Github PK
View Code? Open in Web Editor NEWInkscape extension for exporting drawings as OpenSCAD modules of polygon() calls.
License: Other
Inkscape extension for exporting drawings as OpenSCAD modules of polygon() calls.
License: Other
Per Schmarty, "I pushed an update a couple of days ago to have it keep 5 significant digits. Due to how floats are stored, this can sometimes produce weird long numbers due to small float errors."
For most printing purposes 1 significant digit, and at a maximum 2, would be more than adequate. This would mean precision down to 0.01mm, which is about as fine a feature as anyone would need from an Inkscape->OpenSCAD polygon tool. The current setup (as of 2011/10/23) is creating very long significant digit pairs for XY coordinates. Example, "[-11.556710000000001, -0.96667000000000003]". For my purposes, "[-11.6,-1.0]" would be sufficient.
The plugin works just fine, but these are thrown up.
C:\Users\spamt\AppData\Roaming\inkscape\extensions\openscad-poly.py:31: DeprecationWarning: Effect.OptionParser or `optparse` has been deprecated and replaced with `argparser`. You must change `self.OptionParser.add_option` to `self.arg_parser.add_argument`; the arguments are similar.
self.OptionParser.add_option("--tab",
C:\Users\spamt\AppData\Roaming\inkscape\extensions\openscad-poly.py:47: DeprecationWarning: Effect.affect is now `Effect.run()`. The `output` argument has changed.
e.affect()
C:\Users\spamt\AppData\Roaming\inkscape\extensions\openscad-poly.py:39: DeprecationWarning: self.svg_file is now self.options.input_file.
self.context = OSCADPolyContext(self.svg_file)
C:\Users\spamt\AppData\Roaming\inkscape\extensions\openscad_poly\svg_parser.py:355: DeprecationWarning: simpletransform.parseTransform -> Transform(str).matrix
mat_new = composeTransform(mat_current, parseTransform(node.get("transform")))
C:\Users\spamt\AppData\Roaming\inkscape\extensions\openscad_poly\svg_parser.py:355: DeprecationWarning: simpletransform.composeTransform -> Transform(M1) * Transform(M2)
mat_new = composeTransform(mat_current, parseTransform(node.get("transform")))
C:\Users\spamt\AppData\Roaming\inkscape\extensions\openscad_poly\svg_parser.py:92: DeprecationWarning: simplepath.parsePath -> element.path.to_arrays()
if len(simplepath.parsePath(d)) == 0:
C:\Users\spamt\AppData\Roaming\inkscape\extensions\openscad_poly\svg_parser.py:94: DeprecationWarning: cubicsuperpath.parsePath -> None
p = cubicsuperpath.parsePath(d)
C:\Users\spamt\AppData\Roaming\inkscape\extensions\openscad_poly\svg_parser.py:95: DeprecationWarning: simpletransform.applyTransformToPath -> Path(path).transform(mat)
applyTransformToPath(mat, p)
C:\Users\spamt\AppData\Roaming\inkscape\extensions\openscad_poly\svg_parser.py:61: DeprecationWarning: inkex.bezier.maxdist -> Get maximum distance within bezier curve
if cspsubdiv.maxdist( b ) > flat:
C:\Users\spamt\AppData\Roaming\inkscape\extensions\openscad_poly\svg_parser.py:67: DeprecationWarning: inkex.bezier.beziersplitatt -> Split bezier at given time
one, two = beziersplitatt( b, 0.5 )
C:\Users\spamt\AppData\Roaming\inkscape\extensions\openscad-poly.py:47: DeprecationWarning: Use `save()` or `save_raw()` instead.
e.affect()
I opened an SVG file and tried to export it to OpenSCAD using File -> Save a copy. It crashed with the following message:
Traceback (most recent call last):
File "openscad-poly.py", line 45, in <module>
e.affect()
File "/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/inkex.py", line 268, in affect
self.effect()
File "openscad-poly.py", line 39, in effect
parser.parse()
File "/Users/bzamecnik/.config/inkscape/extensions/openscad_poly/svg_parser.py", line 231, in parse
self.recursivelyTraverseSvg(self.svg, [[0.28222, 0.0, -(self.svgWidth/2.0)], [0.0, -0.28222, (self.svgHeight/2.0)]])
File "/Users/bzamecnik/.config/inkscape/extensions/openscad_poly/svg_parser.py", line 288, in recursivelyTraverseSvg
entity = self.make_entity(node, matNew)
File "/Users/bzamecnik/.config/inkscape/extensions/openscad_poly/svg_parser.py", line 302, in make_entity
entity.load(node,mat)
File "/Users/bzamecnik/.config/inkscape/extensions/openscad_poly/svg_parser.py", line 135, in load
newpath = new_path_from_node(node)
NameError: global name 'new_path_from_node' is not defined
This is the SVG:
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 17.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="5096.659px" height="1203.185px" viewBox="0 0 5096.659 1203.185" enable-background="new 0 0 5096.659 1203.185"
xml:space="preserve">
<path d="M3292.065,752.765l-61.176-173.236c-6.399,90.18-23.767,160.539-52.24,213.287L3292.065,752.765z"/>
<path d="M2539.363,171.933l-275.14,97.162c114.564,13.474,193.766,90.249,193.766,221.161v47.074
c0,88.113-27.763,149.672-101.39,176.226c76.042,24.141,101.39,94.147,101.39,185.882v35.003c0,48.227-9.746,89.341-28.094,122.789
l388.361-137.144h-278.892V171.933z"/>
<path d="M3006.162,494.167c0-213.828-32.84-240.999-87.965-240.999h-151.298v473.173h151.298
C2985.05,726.341,3006.162,660.74,3006.162,494.167z"/>
<path d="M2223.826,892.195v-10.863c0-55.524-33.796-57.937-111.046-61.559l-196.745-8.448v-190.71l196.745-12.07
c83.285-3.622,113.46-3.622,113.46-59.145v-10.863c0-61.559-50.696-61.559-113.46-61.559h-278.822v-55.941l-83.205,29.383
l176.467,499.712h178.318C2199.685,950.132,2223.826,948.926,2223.826,892.195z"/>
<polygon points="2016.582,1203.185 2135.017,1161.361 2001.813,1161.361 "/>
<path d="M3053.834,78.151L3026.236,0l-168.273,59.423h83.692C2984.77,59.423,3021.914,65.961,3053.834,78.151z"/>
</svg>
Same SVG as in #3.
Traceback (most recent call last):
File "openscad-poly.py", line 45, in <module>
e.affect()
File "/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/inkex.py", line 268, in affect
self.effect()
File "openscad-poly.py", line 39, in effect
parser.parse()
File "/Users/bzamecnik/.config/inkscape/extensions/openscad_poly/svg_parser.py", line 229, in parse
self.svgWidth = self.getLength('width', 354) * 0.28222
TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'
Hi Marty,
First of all, thank you for this plug-in, it is fantastic!
Just wanted to let you know that Inkscape installs differently on High Sierra and Mojave.
Official Instructions here
The folder we should copy the src/*
is: /opt/local/share/inkscape/extensions
Thanks,
George
Got an email about possible updates to make:
Thank you for providing this extension for Inkscape users!
This is just to let you know that most 3rd party Inkscape extensions,
like the one you made, probably will not work with the upcoming new
Inkscape version, the long-awaited version 1.0.Here is the info you need to update this extension, so that it will work
with 1.0 and future versions.
https://wiki.inkscape.org/wiki/index.php?title=Updating_your_Extension_for_1.0If you have further questions, you can contact Inkscape developers via
mailing lists (https://lists.inkscape.org/postorius/lists/?all-lists),
forum (https://inkscape.org/forums/extensions/), or the chatroom
(https://chat.inkscape.org/channel/team_devel)If you have already updated it, please disregard this message.
Running Inkscape 1.2.2 on Windows 10.
Copied the contents of the /src folder to C:\Program Files\Inkscape\share\extensions
Opened a .png file, Shift-Alt-B to "Trace Bitmap". Preview contains what I want. Apply.
Select the object, then go to "Path" menu and choose "Object To Path".
Go to "File" and select "Save a Copy". There is no file type for "OpenSCAD polygons" in the filetype menu. (see attached screenshot),
Got the same results after copying the contents of the /src folder to C:\Users[MyUserName]\AppData\Roaming\inkscape\extensions
I use this extension for openSCAD to export .scad file.
But it did not work in python 3 env. So I modify some code to let it works now.
First off, I really appreciate all of the work that you have put into this. If you could do a little more, it would be greatly appreciated. I see that the output has smoothness hardcoded and the relevant(?) line says subdivide_cubic_path(sp, 0.2) # TODO: smoothness preference
. Can you please add that (and anything else helpful) to the interface?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.