Page 1 of 1

Exporting Nodes Coordinates

Posted: Wed Mar 02, 2011 3:39 am
by amigoni
Is there a way to export the coordinates of the nodes of a path?
A simple text or XML file would be ok.

Thanks

Re: Exporting Nodes Coordinates

Posted: Wed Mar 02, 2011 5:08 am
by shawnhcorey
The *.svg files are XML files. Just save it. Note that Inkscape uses translate extensively. That means the coordinates in an object may be translated to another position. You have to add the two together to get the correct coordinates.

Re: Exporting Nodes Coordinates

Posted: Wed Mar 02, 2011 5:14 am
by Simarilius
Heres a quick and dirty extension that will pop up a window with the co-ordinates of the current path. Extract the 2 files to inkscape/share/extensions, then do extensions>export>export XY.
You need to have straight segments or it will dump the coords of the control points as well. You need to make sure the preferences arent set to use relative co-ords as well if you want straight X&Y.

Hope it helps.

Re: Exporting Nodes Coordinates

Posted: Wed Mar 02, 2011 5:21 am
by brynn
Hi amigoni,
Image
Welcome to InkscapeForum!

There was another topic recently about this. If I recall, they were looking to write an extension that would do this, but I don't remember for sure. You could search the forum, because maybe that topic contains a solution. I'll try searching too, and post again if I find it.


shawncorey,
The *.svg files are XML files. Just save it. Note that Inkscape uses translate extensively. That means the coordinates in an object may be translated to another position. You have to add the two together to get the correct coordinates.

"...add the two..." The 2 what? The coordinates from the XML file and what? Sorry, I'm just not clear what you mean :D

Edit
Oops, Sim posted while I was typing :mrgreen: I guess that was the topic I was thinking of :lol:

Re: Exporting Nodes Coordinates

Posted: Wed Mar 02, 2011 5:39 am
by shawnhcorey
brynn wrote:"...add the two..." The 2 what? The coordinates from the XML file and what? Sorry, I'm just not clear what you mean :D


Add the corresponding X and Y from the translate function to the ones in the object to get the correct position.

Re: Exporting Nodes Coordinates

Posted: Fri Mar 04, 2011 12:22 pm
by chriswww
depending on the complexity of the svg drawing and your exact needs, it may be a bit more involved than just grabbing x,y for every control point.

Re: Exporting Nodes Coordinates

Posted: Mon Mar 07, 2011 2:38 pm
by Neon22
To fix the transform issue:
- import simpletransform
- for each path (node.tag == inkex.addNS('path','svg'))
- simpletransform.fuseTransform(node)
Will 'bake' the coordinates into the node (discarding the transform).

You can also get the paths all converted to cubic super paths to handle lines, moves, curves, etc using:
- import cubicsuperpath
- p = cubicsuperpath.parsePath(node.get('d'))
Which returns a nested list of xy values. Always 3 points (first control, point, second control (or handle)

The values will be absolute not relative.
Attached is a modified zip with IMHO improved Export.py file
- transforms the paths so they are "baked" in position.
- always gives absolute point locations.
- prints the nodes and the control points so you can pick what you want.
- you still have to cut and paste from the report window.
- you still need to select the paths you wish to export.

It appears under a new Export category in the Extensions Menu.

Re: Exporting Nodes Coordinates

Posted: Wed Mar 09, 2011 1:59 am
by ~suv
Thanks to both of you - Simarilius and Neon22 - for sharing this tool. Would you consider adding the extension to the list of contributed extensions in the Inkscape Wiki? Getting a list of node coordinates (exported to file or to the clipboard) has been a repeatedly asked question (besides the opposite request to generate a path based on a list of coordinates).

Re: Exporting Nodes Coordinates

Posted: Wed Mar 09, 2011 5:14 am
by Neon22
I would be happy to - and i have some more extensions to add also - its not clear to me how to add them so they end up in he next release. Perhaps I should get on the developers mailing list ?

Re: Exporting Nodes Coordinates

Posted: Wed Mar 09, 2011 6:18 am
by ~suv
Neon22 wrote:I would be happy to - and i have some more extensions to add also - its not clear to me how to add them so they end up in he next release. Perhaps I should get on the developers mailing list ?

Adding an extension to the list in the Wiki and getting an extension accepted and bundled/distributed with Inkscape itself are different procedures.

  • User-Contributed Extensions
    As described on the Wiki page [*], plans are to create a site similar to the GIMP Plugin Registry where user-contributed scripts and other resources can be hosted and searched for. Inkscape's web site itself is currently getting redesigned, and chances are still high that the plans will be realized near- to mid-term (once the main content has been migrated).

    For now, user-contributed extensions need to be externally hosted (be it on Google Code, github, Launchpad or SourceForge, on personal blogs or here in the forum - whatever the author prefers), and can be added to the list, with a short description and the link to the external site hosting the script files.

    An advantage of offering and hosting the extension externally as user contribution is that you will not be bound to Inskcape's release cycles to get updated or enhanced versions out (Inkscape 0.49 is unlikely to be released this year, and any in-between bug fix releases (like 0.48.1) will not include new features).
  • Bundled Extensions
    To get your extension reviewed for bundling with Inkscape, you can submit a report in the bug tracker hosted at Launchpad - with your files attached, as well as a description of intent and usage - to allow testing with different versions on the supported platforms as well as discussing details that might need minor edits or proposals for additional features.

    Maybe you are interested in enhancing the current basic version with additional options - to be of wider use?
    I could imagine that features like
    • optionally select custom units (compare e.g. 'Measure Path…')
    • different output formatting (or at least an infrastructure to add more formats like e.g. CSV, HTML imagemap, etc.),
    • optionally save the output as text file or send it to the system clipboard (if Python supports that in a cross-platform manner)
    would make the extension more versatile and a widely useful tool, complementing Inkscape with basic functionality not provided by internal functions.

Re: Exporting Nodes Coordinates

Posted: Wed Mar 09, 2011 12:23 pm
by ~suv
Neon22 wrote:To fix the transform issue:
- import simpletransform
- for each path (node.tag == inkex.addNS('path','svg'))
- simpletransform.fuseTransform(node)
Will 'bake' the coordinates into the node (discarding the transform).

Your extension seems to actually modify the content of the drawing and - if applied to transformed shapes - reports incorrect coordinates and in the end deletes the preserved transformation of the shape without updating its parameters (causing the shape to be moved, resized or otherwise changing its geometry). This should not happen when calling an extension with the intent of getting information only about the selected object(s).

To reproduce:
  • draw a circle
  • move, scale, stretch or skew it (this adds a preserved transformation to the shape)
  • with the circle selected, call 'Extensions > Export > Export XY' (works with shapes as well) and close the window with the node list
Result: -> the circle is reverted to the original location/size/proportion

IMHO the flattening of the transforms should not (or only optionally) be stored in the file. Ideally - if doable - the script does the calculations, pipes the resulting list to stderr (-> Inkscape) and quits without even causing an entry in the Undo list (I don't know whether the described workaround for bug #166697 would be applicable here and still allow to return the list per stderr).

Re: Exporting Nodes Coordinates

Posted: Wed Mar 09, 2011 6:05 pm
by ~suv
~suv wrote:(…) reports incorrect coordinates (…)

Sorry - I was wrong about that: for my example using an ellipse (circle) it returned an unexpected conversion of the path data (the way the 'A' path command was interpreted) which does not correspond to the result of converting an ellipse to path using 'Path > Object to Path'. The coordinates themselves are correct in their absolute values and reflect the applied transformation.

However, the path data of the shape should not returned modified after exporting XY without also updating the shape parameters (if they need to be modified at all). Else it would be better to exclude parameterized shapes (ellipse, star/polygon, spiral) from being parsed by the extension.

Re: Exporting Nodes Coordinates

Posted: Wed Mar 09, 2011 9:40 pm
by Neon22
yes - good idea much safer - I expect I will make a deepcopy and then delete the transformed result.
I can't get access to object-to-path its not exposed (same as union or many other tools)
SO I guess I will have to skip all non-paths

Re: Exporting Nodes Coordinates

Posted: Thu Mar 10, 2011 4:25 am
by Simarilius
Since I code on inkscape anyways I'm more than happy for it to go into head, I did however base mine off a blog post at http://jumpnslide.tumblr.com/ which doesnt explicitly state a license, have asked Jean to confirm hes happy with that.

Update - Jean has confirmed he's fine with it.

Re: Exporting Nodes Coordinates

Posted: Tue Dec 13, 2011 4:40 pm
by chamois
Dear all or neon22,

Can please help to tell me where the coordinates go to after running ExportXY at Extensions->Export ?
I only get these new files in share/extensions directory:
bezmisc.py
cubicsuperpath.pyc
simplepath.pyc
simplestyle.pyc
simpletransform.pyc

Thank you very much.
Mei

Re: Exporting Nodes Coordinates

Posted: Wed Dec 14, 2011 7:10 am
by Neon22
It does not write out to a file. Instead it shows you the data in a small popup window.
Then you need to manually cut and paste it into some other file for your use.

Re: Exporting Nodes Coordinates

Posted: Fri Oct 05, 2012 1:58 pm
by jeffz2012
this does not work in Vista (with UAC off)
No result window shows ... just a quick blip informing that mod works.

Re: Exporting Nodes Coordinates

Posted: Tue Jan 15, 2013 8:02 am
by geotheory
Useful little script, thanks Simarilius for sharing. Just to note that it was omitting the last vertex of each path object because of line 37 of the script

Code: Select all

for i in range( len(pathData)-1):
. You can correct this by replacing it with:

Code: Select all

for i in range( len(pathData)):

Good node hunting ;)

Re: Exporting Nodes Coordinates

Posted: Tue Jan 15, 2013 8:17 am
by geotheory
In addition, line 17:

Code: Select all

for node in self.selected.iteritems():
is a duplication of line 23 and causes data output duplication. Suggest removal.

Re: Exporting Nodes Coordinates

Posted: Wed May 20, 2015 6:24 am
by Nathan1123
I get an error when I attempt to use this extension:

Traceback (most recent call last):
File "ExportXY.py", line 57, in <module>
effect.affect()
File "/home/name/.config/inkscape/extensions/inkex.py", line 151, in affect
self.getposinlayer()
File "/home/name/.config/inkscape/extensions/inkex.py", line 128, in getposinlayer
doc_height = unittouu(self.document.getroot().get('height'))
File "/home/name/.config/inkscape/extensions/inkex.py", line 43, in unittouu
p = param.match(string)
TypeError: expected string or buffer

Using Inkscape 0.91 on Ubuntu

What did I do wrong?!

Re: Exporting Nodes Coordinates

Posted: Wed May 20, 2015 7:38 am
by Lazur
Nathan1123 wrote:What did I do wrong?!


You probably use 0.91 and the extension is not compatible -Probably dependencies changed to other location? Or worse, you run a 64bit version while the code was written for 32 bit.- Not sure, just guessing.


Other than that, with the xml editor you can get straight to node coordinates, in a way.
("M" or "m", transformations can make it tricky.)

Re: Exporting Nodes Coordinates

Posted: Wed May 20, 2015 4:00 pm
by ragstian
Hi.
Nathan wrote:What did I do wrong?!

You did nothing wrong, the handling of units changed from 0.48 to 0.91. You can fix this easily by editing the extension python file and change the inkex.unittouu to self.unittouu

The extensions does work the same way for both the 32-bit and 64-bit versions.

There are a few other posts on this forum on the subject , do a forum search for unittouu to find the posts.
(By the way unittouu is an abbreviation for "unit to user unit")

Chime back if you don't want to mess with your extension file yourself.

Re: Exporting Nodes Coordinates

Posted: Thu May 21, 2015 2:22 am
by Nathan1123
ragstian wrote: You can fix this easily by editing the extension python file and change the inkex.unittouu to self.unittouu


Are you sure that's all I have to do? Because I tried to add that in the inkex.py file and I got this error:

AttributeError: TemplateEffect instance has no attribute 'unittouu'

I have attached the source code for inkex.py if you want to take a look at it

Thanks

Re: Exporting Nodes Coordinates

Posted: Thu May 26, 2016 1:45 pm
by plasterdapper
Video of the problem https://youtu.be/qHi8svcCv7Q

Hello, I'm trying to use this tool with openscad. If you just change the output string to this it will copy and paste into the polygon(points=[]); function nicely.

outputString += "[" + str(x) + "," + str(y) + "]" + "," + "\n"

I've read all the threads here but no one has an answer to the transform problem. It seems to be a thousand MM off in the Y axis every time. It would be really nice to solve this. I zero and center the object in Inkscape before exportxy.

Re: Exporting Nodes Coordinates

Posted: Sun Jun 26, 2016 8:21 am
by Simarilius
can I suggest you take a look at http://www.thingiverse.com/thing:25036 if your wanting to do openscad export?