Exporting Nodes Coordinates

Post questions on how to use or achieve an effect in Inkscape.

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
amigoni
 
Posts: 1
Joined: Wed Mar 02, 2011 3:37 am

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.
User avatar
shawnhcorey
 
Posts: 113
Joined: Mon Jan 07, 2008 12:17 pm

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 1006 times
Simarilius
 
Posts: 612
Joined: Wed Jun 06, 2007 2:37 am

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:
Basics:
> Help menu > Tutorials
> a Quick Guide to Inkscape
Manual:
> Inkscape: Guide to a Vector Drawing Program
Tutorials:
> Inkscape Community
Development news
> Google+
Gallery:
> Inkscape Community Gallery
User avatar
brynn
 
Posts: 6783
Joined: Wed Sep 26, 2007 4:34 pm
Location: western USA

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.
User avatar
shawnhcorey
 
Posts: 113
Joined: Mon Jan 07, 2008 12:17 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.
chriswww
 
Posts: 383
Joined: Fri Nov 19, 2010 3:04 pm

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 632 times
Neon22
 
Posts: 11
Joined: Mon Mar 07, 2011 10:31 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).
~suv
 
Posts: 1957
Joined: Sun May 10, 2009 2:07 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 ?
Neon22
 
Posts: 11
Joined: Mon Mar 07, 2011 10:31 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: 1957
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: 1957
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.
~suv
 
Posts: 1957
Joined: Sun May 10, 2009 2:07 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
Neon22
 
Posts: 11
Joined: Mon Mar 07, 2011 10:31 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.
Simarilius
 
Posts: 612
Joined: Wed Jun 06, 2007 2:37 am

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
chamois
 
Posts: 1
Joined: Tue Dec 13, 2011 4:30 pm

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.
Neon22
 
Posts: 11
Joined: Mon Mar 07, 2011 10:31 am

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.
jeffz2012
 
Posts: 1
Joined: Fri Oct 05, 2012 1:56 pm

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.
User avatar
geotheory
 
Posts: 11
Joined: Wed Jan 09, 2013 9:23 pm
Location: London, UK


Return to Help with using Inkscape

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Google Adsense [Bot], Yahoo [Bot] and 13 guests