Coder Social home page Coder Social logo

inkscape-openscad-poly's Introduction

OpenSCAD Polygon Output for Inkscape

This is an Inkscape extension that allows you to save your Inkscape drawings as OpenSCAD (.scad) files containing modules with 2D polygons suitable for extruding into 3D shapes.

Website: http://github.com/martymcguire/inkscape-openscad-poly

Contributors

Credits

Install

Copy the contents of src/ to your Inkscape extensions/ folder.

To find this folder you will need to check the instructions for your specific operating system and Inkscape installation type.

An incomplete list of possible locations by platform:

  • OS X - /Applications/Inkscape.app/Contents/Resources/extensions
  • Linux - /usr/share/inkscape/extensions
  • Windows - C:\Program Files\Inkscape\share\extensions

Usage

  • Size and locate your image appropriately:
    • Setting units to mm in Inkscape makes it easy to size your drawing.
    • The extension will automatically attempt to center everything.
  • Convert all text to paths:
    • Select all text objects.
    • Choose Path | Object to Path.
  • Save as OpenSCAD:
    • File | Save a Copy.
    • Select OpenSCAD Polygons (*.scad).
    • Save your file.

Use in OpenSCAD

You'll find each path from your Inkscape file appears as a module in the resulting OpenSCAD file.

The resulting OpenSCAD also contains a list of every generated module at the beginning. This allows easy control of the generated polygons by simply previewing in OpenSCAD (with F5 key) and can be easily disabled by commenting out or deleting the lines. If the paths in the SVG file use simple basic colors (no color gradient) this color is also transformed into an OpenSCAD color() statement and added before the module. Be aware that unfortunately OpenSCAD uses color only in preview mode (F5) not in render mode (F6).

For example:

// my_drawing.scad
module badge_face() {
  polygon(points=
	[[-16.704628355490897, -20.69348168358303], [-13.479257330090903, -35.207652708983034], [-2.1904573300909078, -23.918852708983053], [17.161771644509102, -71.493081683583029], [-11.866570406290904, -40.045710658183026], [-13.479257330090903, -63.429652708983014], [-36.056857330090907, -56.172565785182996], [-30.412457330090902, -2.9539396327830048], [-0.57777040629089527, -1.3412527089830064], [16.355429593709104, -20.693481683583002], [38.126687542909096, -57.785252708983023]]
	, paths=
	[[0, 1, 2, 0], [3, 4, 5, 6, 7, 8, 9, 10, 3]]
	);}

You can include this file in your OpenSCAD program and use OpenSCAD's 2D-to-3D extrusion methods, calling these modules to get the 2D data!

// my_object.scad
include <a_badge.scad>;

linear_extrude(height=20)
  badge_face();

TODOs

  • Use square and circle where applicable for simplicity?
  • Combine layer contents into single modules?
  • Parameterize smoothness for curve approximation (dirty workaround: Scale up in inkscape and down in OpenSCAD).
  • Include example files/templates.

Special attribution notes

inkscape-openscad-poly's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

inkscape-openscad-poly's Issues

Limiting significant digits

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.

NameError: global name 'new_path_from_node' is not defined

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>

Other units than px, % or none (such as mm) should be handled

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'

Extension does not show up in Inkscape 1.2 for Windows

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

InkscapeSaveCopy

Parameters

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?

Changes for Inkscape 1.0?

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.0

If 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.

Deprecation Warnings with Inkscape 1.1.1 (3bf5ae0d25, 2021-09-20)

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()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.