2

So I saw the polygon tool in inkscape and I expected the code of the polygon shapes to be something in the lines of

<polygon points="215,110 0, 110 0, 0 47.7, 0 215,0" fill="blue" />

however it creates a path instead, like so.

<path id="path1495" d="M 1933.1674,824.59603 H 0 V 0 h 1933.1674 z" fill="pink" />

Does anyone know how to get polygon points like in the first snippet?

6
  • 1
    Hi. Welcome to GDSE. As far as I know, there's no way to do that in Inskcape. However Inkscape does support displaying an SVG polygon, if you were add one manually to the code. To edit the points in Inkscape you could then use the XML editor. Out of interest, why do you need an actual SVG polygon? What problem are you trying to solve by using one?
    – Billy Kerr
    Feb 8, 2020 at 16:23
  • If the OP is an openSCAD user, there's a bit of gain to be had to be able to read the code after creating a polygon. One can take the data directly from the code and enter it into openSCAD rather than perform calculations in a stand-alone manner.
    – fred_dot_u
    Feb 9, 2020 at 1:05
  • @fred_dot_u - that's really interesting, but I'd rather hear the OPs reason for needing an SVG polygon before attempting an answer. Currently, this looks like a possible XY problem.
    – Billy Kerr
    Feb 9, 2020 at 13:07
  • @BillyKerr I am not an OpenSCAD user however I need it in SVG Polygon for use in the web where the context specifically needs to be in polygon points(no other choice due to how the custom code is built)
    – Fanna1119
    Feb 9, 2020 at 15:04
  • In that case, I think manually adding an SVG polygon element in the code is probably the best solution if this is a one-off task. From there you can open in Inkscape and manually edit the points in the XML editor. The maths of the actual conversion to points could be handled using Fred's work-around. Of course it may even be possible to write an extension to do it all automatically in Inkscape, perhaps even using the OpenScad extension as a starting point. Unfortunately writing such an extension is not something I can help with. Or perhaps you could make an Inkscape feautre request.
    – Billy Kerr
    Feb 9, 2020 at 15:26

1 Answer 1

2

This is a work-around that works for simple shapes, and my test was specifically with a pentagon as implied with the question data.

There is an extension for Inkscape known as "Inkscape to OpenSCAD" which takes the design created in the edit window and converts it to multiple paths (if more than one shape) in OpenSCAD format. There are earlier and later versions of the same code on Thingiverse, but version 7 changed in some way to make it unsuitable to me, but I can't recall why.

The test I created for this answer resulted in a six point array with an arbitrary 1 mm extrusion figure, which can be ignored for your objective.

A randomly placed pentagon resulted in a small file, the primary line containing:

path3409_0_points = [[34.404944,55.348279],[-37.074095,53.945019],[-57.827755,-14.469214],[0.824817,-55.348279],[57.827755,-12.198694],[34.404944,55.348279]];

If care had been taken with the placement and size of the pentagon, one can expect numbers resembling integers rather than this scattered array, but the results are consistent with the objective.

The removal of the duplicated last element of the array did not change the appearance of the extruded polygon.

inkscape/openscad polygon

2
  • I will have a look at this thank you. If by "simple shapes" you mean 2D shapes then yes!
    – Fanna1119
    Feb 9, 2020 at 14:40
  • By simple, I meant single continguous paths, one per file. If the pentagon, for instance, had a cut-out in the center, Inkscape to OpenSCAD would generate two paths, which may not be a problem, generally speaking.
    – fred_dot_u
    Feb 9, 2020 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.