Exporting Nodes Coordinates
Exporting Nodes Coordinates
Is there a way to export the coordinates of the nodes of a path?
A simple text or XML file would be ok.
Thanks
A simple text or XML file would be ok.
Thanks
- shawnhcorey
- Posts: 149
- Joined: Mon Jan 07, 2008 12:17 pm
Re: Exporting Nodes Coordinates
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.
-
- Posts: 626
- Joined: Wed Jun 06, 2007 2:37 am
Re: Exporting Nodes Coordinates
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.
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
Re: Exporting Nodes Coordinates
Hi amigoni,
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,
"...add the two..." The 2 what? The coordinates from the XML file and what? Sorry, I'm just not clear what you mean
Edit
Oops, Sim posted while I was typing I guess that was the topic I was thinking of
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
Edit
Oops, Sim posted while I was typing I guess that was the topic I was thinking of
Basics - Help menu > Tutorials
Manual - Inkscape: Guide to a Vector Drawing Program
Inkscape Community - Inkscape FAQ - Gallery
Inkscape for Cutting Design
Manual - Inkscape: Guide to a Vector Drawing Program
Inkscape Community - Inkscape FAQ - Gallery
Inkscape for Cutting Design
- shawnhcorey
- Posts: 149
- Joined: Mon Jan 07, 2008 12:17 pm
Re: Exporting Nodes Coordinates
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
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
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
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.
- 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
Re: Exporting Nodes Coordinates
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
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
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)
- …
Re: Exporting Nodes Coordinates
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
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
~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
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
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
-
- Posts: 626
- Joined: Wed Jun 06, 2007 2:37 am
Re: Exporting Nodes Coordinates
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.
Update - Jean has confirmed he's fine with it.
Re: Exporting Nodes Coordinates
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
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
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.
Then you need to manually cut and paste it into some other file for your use.
Re: Exporting Nodes Coordinates
this does not work in Vista (with UAC off)
No result window shows ... just a quick blip informing that mod works.
No result window shows ... just a quick blip informing that mod works.
Re: Exporting Nodes Coordinates
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 . You can correct this by replacing it with:
Good node hunting
Code: Select all
for i in range( len(pathData)-1):
Code: Select all
for i in range( len(pathData)):
Good node hunting
Re: Exporting Nodes Coordinates
In addition, line 17: is a duplication of line 23 and causes data output duplication. Suggest removal.
Code: Select all
for node in self.selected.iteritems():
-
- Posts: 6
- Joined: Wed May 20, 2015 3:16 am
Re: Exporting Nodes Coordinates
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?!
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
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
Hi.
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.
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
( ͡° ͜ʖ ͡°)
RGDS
Ragnar
-
- Posts: 6
- Joined: Wed May 20, 2015 3:16 am
Re: Exporting Nodes Coordinates
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
-
- Posts: 1
- Joined: Thu May 26, 2016 1:02 pm
Re: Exporting Nodes Coordinates
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.
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.
-
- Posts: 626
- Joined: Wed Jun 06, 2007 2:37 am
Re: Exporting Nodes Coordinates
can I suggest you take a look at http://www.thingiverse.com/thing:25036 if your wanting to do openscad export?