Exporting Nodes Coordinates

Post questions on how to use or achieve an effect in Inkscape.
amigoni
Posts: 1
Joined: Wed Mar 02, 2011 3:37 am

Exporting Nodes Coordinates

Postby amigoni » Wed Mar 02, 2011 3:39 am

Is there a way to export the coordinates of the nodes of a path?
A simple text or XML file would be ok.

Thanks

User avatar
shawnhcorey
Posts: 149
Joined: Mon Jan 07, 2008 12:17 pm

Re: Exporting Nodes Coordinates

Postby shawnhcorey » Wed Mar 02, 2011 5:08 am

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.

Simarilius
Posts: 626
Joined: Wed Jun 06, 2007 2:37 am

Re: Exporting Nodes Coordinates

Postby Simarilius » Wed Mar 02, 2011 5:14 am

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.
Attachments
ExportXY.zip
XY export extension
(1.38 KiB) Downloaded 3288 times

User avatar
brynn
Posts: 10309
Joined: Wed Sep 26, 2007 4:34 pm
Location: western USA
Contact:

Re: Exporting Nodes Coordinates

Postby brynn » Wed Mar 02, 2011 5:21 am

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:

User avatar
shawnhcorey
Posts: 149
Joined: Mon Jan 07, 2008 12:17 pm

Re: Exporting Nodes Coordinates

Postby shawnhcorey » Wed Mar 02, 2011 5:39 am

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.

chriswww
Posts: 383
Joined: Fri Nov 19, 2010 3:04 pm

Re: Exporting Nodes Coordinates

Postby chriswww » Fri Mar 04, 2011 12:22 pm

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.

Neon22
Posts: 11
Joined: Mon Mar 07, 2011 10:31 am

Re: Exporting Nodes Coordinates

Postby Neon22 » Mon Mar 07, 2011 2:38 pm

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.
Attachments
Export.zip
unpack into \Inkscape\share\extensions with all the others. Look in Export category under Extensions Menu.
(1.3 KiB) Downloaded 1863 times

~suv
Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: Exporting Nodes Coordinates

Postby ~suv » Wed Mar 09, 2011 1:59 am

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

Neon22
Posts: 11
Joined: Mon Mar 07, 2011 10:31 am

Re: Exporting Nodes Coordinates

Postby Neon22 » Wed Mar 09, 2011 5:14 am

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 ?

~suv
Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: Exporting Nodes Coordinates

Postby ~suv » Wed Mar 09, 2011 6:18 am

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.

~suv
Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: Exporting Nodes Coordinates

Postby ~suv » Wed Mar 09, 2011 12:23 pm

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

~suv
Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: Exporting Nodes Coordinates

Postby ~suv » Wed Mar 09, 2011 6:05 pm

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

Neon22
Posts: 11
Joined: Mon Mar 07, 2011 10:31 am

Re: Exporting Nodes Coordinates

Postby Neon22 » Wed Mar 09, 2011 9:40 pm

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

Simarilius
Posts: 626
Joined: Wed Jun 06, 2007 2:37 am

Re: Exporting Nodes Coordinates

Postby Simarilius » Thu Mar 10, 2011 4:25 am

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.

chamois
Posts: 1
Joined: Tue Dec 13, 2011 4:30 pm

Re: Exporting Nodes Coordinates

Postby chamois » Tue Dec 13, 2011 4:40 pm

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

Neon22
Posts: 11
Joined: Mon Mar 07, 2011 10:31 am

Re: Exporting Nodes Coordinates

Postby Neon22 » Wed Dec 14, 2011 7:10 am

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.

jeffz2012
Posts: 1
Joined: Fri Oct 05, 2012 1:56 pm

Re: Exporting Nodes Coordinates

Postby jeffz2012 » Fri Oct 05, 2012 1:58 pm

this does not work in Vista (with UAC off)
No result window shows ... just a quick blip informing that mod works.

User avatar
geotheory
Posts: 11
Joined: Wed Jan 09, 2013 9:23 pm
Location: London, UK

Re: Exporting Nodes Coordinates

Postby geotheory » Tue Jan 15, 2013 8:02 am

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

User avatar
geotheory
Posts: 11
Joined: Wed Jan 09, 2013 9:23 pm
Location: London, UK

Re: Exporting Nodes Coordinates

Postby geotheory » Tue Jan 15, 2013 8:17 am

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.

Nathan1123
Posts: 6
Joined: Wed May 20, 2015 3:16 am

Re: Exporting Nodes Coordinates

Postby Nathan1123 » Wed May 20, 2015 6:24 am

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?!

Lazur
Posts: 4717
Joined: Tue Jun 14, 2016 10:38 am

Re: Exporting Nodes Coordinates

Postby Lazur » Wed May 20, 2015 7:38 am

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

User avatar
ragstian
Posts: 1181
Joined: Thu Oct 11, 2012 2:44 am
Location: Stavanger-Norway

Re: Exporting Nodes Coordinates

Postby ragstian » Wed May 20, 2015 4:00 pm

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.
Good Luck!
( ͡° ͜ʖ ͡°)
RGDS
Ragnar

Nathan1123
Posts: 6
Joined: Wed May 20, 2015 3:16 am

Re: Exporting Nodes Coordinates

Postby Nathan1123 » Thu May 21, 2015 2:22 am

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
Attachments
inkex.zip
(2.79 KiB) Downloaded 423 times

plasterdapper
Posts: 1
Joined: Thu May 26, 2016 1:02 pm

Re: Exporting Nodes Coordinates

Postby plasterdapper » Thu May 26, 2016 1:45 pm

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.

Simarilius
Posts: 626
Joined: Wed Jun 06, 2007 2:37 am

Re: Exporting Nodes Coordinates

Postby Simarilius » Sun Jun 26, 2016 8:21 am

can I suggest you take a look at http://www.thingiverse.com/thing:25036 if your wanting to do openscad export?


Return to “Help with using Inkscape”