Is it possible to simply export the coordinates of selected nodes to text? My use is for a physics platformer game where I place nodes on the ground that will be used as coordinates for drawing a physics ground with polygons in game. Right now I am simply copy pasting each x and y value of each node manually from Inkscape and into my developing tool. But obviously that is pretty tedious. A text export would be wonderful because it would allow me to automatically read the text file when importing the coordinates. Hope someone can help with this?
**UPDATE**
I have finished modifying the extension to fit my needs. I named it ExportGuiXY and works with 0.48, but not with 0.91. Here is zip with the modified extension ExportGuiXY: https://www.dropbox.com/s/wxf4swqv0e5g3 ... Y.zip?dl=0
Btw in the .inx file there is an id entry with a namespace link. I haven't changed that because I am modifying an existing extension, but do I have to change it to my own namespace or? I am new to extensions so not sure what to do/not to do here.
From my testing all paths x and y coordinates, as they would be shown in the GUI, will now be printed to the error dialog, regardless of the off coord values in the SVG. I have tested with a number of my other paths I have made weeks ago before I began trying to do this and they also give the correct results when I check them. So it seems to actually work! yay
So the whole idea of this is to avoid having to go through the tedium of checking each nodes x and y in the GUI and simply have the extension print a list of it. Paths must have straight line segments no curves etc and not loop.
1. Select the path and note the GUI x and y of the first node in the path. The first node in the path is the node that Inkscape considers as the "first" node, presumably(always?) the node that was first created in the path so you have to know which node begins the path.... Also first node coords must be integers, so no decimals. I use snapping to place the nodes to ensure this.
2. Flip the path.
3. Select path and select all nodes in path with ctrl-a and move them all at once so that the first node is at the same x and y as it was before the flip.
4. Run the exportGuiXY extension from the extension menu under Export and input the first node x and y you noted in 1, press apply. Extension prints to dialog the correct x and y coords as they would have been shown in the GUI.
An improvement would be to have the extension automatically calculate the flipped x,y of the svg (without actually flipping the path about the first node) to make it even easier for the user. Also since I am completely new to extensions and Python I expect the code I have added and modified could be optimized.
Issues: input dialog box does not close automatically on clicking Apply, must also click Close. Clicking Apply again instead of Close raises an error.
The most ideal thing would of course be to have an extension that could simply read the values directly of the X: and Y: boxes in the GUI. But I have found no way of doing that anywhere so I don't know if it is even possible...
[solved] Export node coordinates as text?
[solved] Export node coordinates as text?
Last edited by toxigames on Sun Sep 13, 2015 8:27 am, edited 7 times in total.
-
- Posts: 38
- Joined: Tue Aug 11, 2015 5:53 am
Re: Export node coordinates as text?
It shouldn't be too difficult to create a tool in php or python (or even JavaScript) to extract the required data from an svg file, but I doubt it's possible directly from Inkscape. As it's a very rare requirement I doubt that there will be the effort available amongst the Inkscape developers.
Re: Export node coordinates as text?
Thanks for the reply styxlawyer I wonder why it's a rare request? I would think it was more often requested by game developers. Because in Inkscape it's really easy and works very well visually making a path to match the graphic and use the coordinates for creating the physics shape in game development. It's getting the coordinates that is the tedious part and takes up a huge amount of time. Perhaps there are just not many game developers using Inkscape for creating graphics for use with shapes?
Re: Export node coordinates as text?
This was a somewhat similar topic recently:
http://www.inkscapeforum.com/viewtopic.php?f=5&t=19359
-svg is an xml kind of file, containing the "exact" coordinates of the objects, so you can copy/paste straight from the xml editor (Shift+Ctrl+X) the path's node coordinates if you like.
BUT
there are possible transformations that can mess up the values, as well as the viewbox setting (inkscape still uses a vertically flipped coordinate system compared to the specs -requested feature several times to make it customize-able).
http://www.inkscapeforum.com/viewtopic.php?f=5&t=19359
-svg is an xml kind of file, containing the "exact" coordinates of the objects, so you can copy/paste straight from the xml editor (Shift+Ctrl+X) the path's node coordinates if you like.
BUT
there are possible transformations that can mess up the values, as well as the viewbox setting (inkscape still uses a vertically flipped coordinate system compared to the specs -requested feature several times to make it customize-able).
Re: Export node coordinates as text?
Yes, search the forum. This request does come up from time to time. I seem to recall there was even some discussion about someone making an extension that will do that. I don't think that ever came to pass, but they might have posted the script they made, to do this job.
Here's the extension repository -- maybe something there will help? http://wiki.inkscape.org/wiki/index.php ... Repository
Here's the extension repository -- maybe something there will help? http://wiki.inkscape.org/wiki/index.php ... Repository
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
Re: Export node coordinates as text?
brynn wrote:Yes, search the forum. This request does come up from time to time. I seem to recall there was even some discussion about someone making an extension that will do that. I don't think that ever came to pass, but they might have posted the script they made, to do this job.
Here's the extension repository -- maybe something there will help? http://wiki.inkscape.org/wiki/index.php ... Repository
Okay so I have thought about this and searched for an extension. I found one, called exportXY, here viewtopic.php?f=5&t=8826. It's the one that was modified and attached in that thread by Neon22 » Mon Mar 07, 2011 2:38 pm. It will print to Inkscapes error dialog the coordinates and from looking in my SVG file the output matches the values saved in the SVG for the selected path in question. However the coordinates are strange, and off by some obscure value I can't seem to figure out where comes from. It seems to vary randomly from path to path and from document to document? As example in my project I have some coordinates on a path, and the path being the only thing in my document; so no other objects or paths etc. (Example SVG: Left-click, or right-click-open in new window (but don't right-click-save!) the following link to go to my Dropbox to download my example SVG if is of any use for someone reading this thread in understanding the issue/solution: https://www.dropbox.com/s/d9fxanywh8oag ... 1.svg?dl=0) The first 3 coords of the path are 0,53 6,55 10,59, lets look at them. In the exportXY extensions output and in the SVG file the y-coords are something else though: 0,999.36219 6,997.36219 10,993.36219. Previous poster wrote that Inkscape actually uses an inverted vertical coord system than what is displayed in the UI which leads me to think that I should mirror flip the path about the first coord of the path to be able to calculate the correct UI coords. So flipping the path about it's first node's y coord the coords in the extension output and ind the SVG are now this: 0,999.36219 6,1001.3622 10,1005.3622. From the first SVG y-coord I subtract the UI coord: 999.36219 - 53 = 946.36219. That must be the off value that I need to also subtract for each of the rest of the SVG coords, so the second y-coord: 1001.3622 - 946.36219 = 55.00001 (that matches the (non-flipped)UI y-coord for the second node, except for 0.00001, but that seems to stem from a 8-digit limitation on coords in Inkscape, so not related with the issue at hand, but I'll have to deal with that also for automatic calculation and final output). The third y-coord: 1005.3622 - 946.36219 = 59.00001. Again a match with the (non-flipped) UI y-coord except for the 8-digit limit.
I guess a pseudo formular could be something like this:
Code: Select all
for each node{
Correct y-coord in non flipped path as displayed in Y-coord as displayed in Inkscapes UI = svg/extension.nodeYFlippedPath - (svg/extension.firstNodeY - UI.firstNodeY).
}
However I have no knowledge of python or scripting so I don't know how to code some workable code into the exportXY extension, so that it instead outputs the calculated UI-cordinates, and not the strangely transformed y-coordinates as it is written in the SVG. Maybe someone can help with that? Else I'll just have to study some Python and Inkscape extension tutorials I guess Where would be the best place to start with that? In any case thanks for the help this far to all of you
Re: Export node coordinates as text?
For your awesome detective work -- do you understand why they values are off by just a little? Is it entirely because of the 8-digit limit? (There are also messages in this forum about increasing the number of decimal places.....but I think that's for the gui....and I'm not sure where you see the 8 digit limit.)
Could the small errors be related to the stroke width? I don't think the stroke width affects the coordinates at all. But I don't understand how the extension works.....and that's the first thing that comes to mind for small, mysterious size differences.
While I understand what you want to achieve, I don't understand much about how. But in the topic you found, it looks like it contains a finished extension. Does it not work for your particular needs? Or does it not work with 0.91?
Maybe you could contact the extension author (via PM)?
You know, I avoided subscribing to Inkscape mailing lists for years, because I just don't like using that kind of format. But as a matter of fact, that's what the developers use, and that's the best way to reach developers, or just members with (what I see as) advanced skills, who potentially could do this kind of thing.
So much as I understand how frustrating it is, I would suggest posting this to the User mailing list. If you don't want to join, I could post a message for you, linking to this topic.
Could the small errors be related to the stroke width? I don't think the stroke width affects the coordinates at all. But I don't understand how the extension works.....and that's the first thing that comes to mind for small, mysterious size differences.
While I understand what you want to achieve, I don't understand much about how. But in the topic you found, it looks like it contains a finished extension. Does it not work for your particular needs? Or does it not work with 0.91?
Maybe you could contact the extension author (via PM)?
You know, I avoided subscribing to Inkscape mailing lists for years, because I just don't like using that kind of format. But as a matter of fact, that's what the developers use, and that's the best way to reach developers, or just members with (what I see as) advanced skills, who potentially could do this kind of thing.
So much as I understand how frustrating it is, I would suggest posting this to the User mailing list. If you don't want to join, I could post a message for you, linking to this topic.
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
Re: Export node coordinates as text?
brynn wrote:For your awesome detective work -- do you understand why they values are off by just a little? Is it entirely because of the 8-digit limit? (There are also messages in this forum about increasing the number of decimal places.....but I think that's for the gui....and I'm not sure where you see the 8 digit limit.)
Could the small errors be related to the stroke width? I don't think the stroke width affects the coordinates at all. But I don't understand how the extension works.....and that's the first thing that comes to mind for small, mysterious size differences.
While I understand what you want to achieve, I don't understand much about how. But in the topic you found, it looks like it contains a finished extension. Does it not work for your particular needs? Or does it not work with 0.91?
Maybe you could contact the extension author (via PM)?
You know, I avoided subscribing to Inkscape mailing lists for years, because I just don't like using that kind of format. But as a matter of fact, that's what the developers use, and that's the best way to reach developers, or just members with (what I see as) advanced skills, who potentially could do this kind of thing.
So much as I understand how frustrating it is, I would suggest posting this to the User mailing list. If you don't want to join, I could post a message for you, linking to this topic.
I was testing first in 0.48 because the exportXY extension is old from 2011. But after I also tested in 0.91 with the same results.
The small coord deviation can't be related to the exportXY extension because it happened before I even installed that exportXY extension. The 8-digit limit I am seeing is happening in the SVG itself. Form the tests I have made there is never more than 8 digits for the path coords in the SVG. The coords in the GUI seems to be able to have more than 8 digits though, but in the SVG it's max 8 digits. If you take one of the node coords from my SVG before I flipped the path it's 999.36219. So there are three digits before the punctuation (the 999. part) and five decimal digits after the punctuation (the .36219 part), 8 digits in total. After I flipped the path however the SVG coord was changed to 1000.3622. So that's four digits before the punctuation (the 1000. part) but only four digits after the punctuation (the .3622 part), but still 8 digits in total. That is why I believe that .36219 was being rounded up to .3622 and also why I thought it some 8-digit limitation somewhere in Inkscape since the total digits are still 8 while I think it should have been 9 (1000.36219). Anyways I don't think it matters much for my purpose because for shape coords in a physics game simulation I could just round to nearest whole number and that should be perfectly fine.
Re: Export node coordinates as text?
In the prefs you can set higher values.
With numeric precision at 16 and
minimum exponent at -32
you can use coordinates like -274.2857055664063.
Even if the mentioned behave is present, it's a bit better.
In 0.91 you can set the path to be saved as a series of absolute or relative movements -M and m?-.
Maybe relative can use decimals more effectively on precision, while you are after absolute coordinates I'm guessing.
Saving the image again with the right settings should affect the codes, but needs some action taken to be done.
Like click twice on the eye at the bottom (hide and show layer).
With numeric precision at 16 and
minimum exponent at -32
you can use coordinates like -274.2857055664063.
Even if the mentioned behave is present, it's a bit better.
In 0.91 you can set the path to be saved as a series of absolute or relative movements -M and m?-.
Maybe relative can use decimals more effectively on precision, while you are after absolute coordinates I'm guessing.
Saving the image again with the right settings should affect the codes, but needs some action taken to be done.
Like click twice on the eye at the bottom (hide and show layer).
Re: Export node coordinates as text?
Lazur URH wrote:In the prefs you can set higher values.
With numeric precision at 16 and
minimum exponent at -32
you can use coordinates like -274.2857055664063.
Even if the mentioned behave is present, it's a bit better.
In 0.91 you can set the path to be saved as a series of absolute or relative movements -M and m?-.
Maybe relative can use decimals more effectively on precision, while you are after absolute coordinates I'm guessing.
Saving the image again with the right settings should affect the codes, but needs some action taken to be done.
Like click twice on the eye at the bottom (hide and show layer).
oh nice, I didn't know that. I guess I should have searched the preferences a little more closely!
Anyway I think I have finished modifying the extension to fit my needs. I named it ExportGuiXY. Here is zip with the modified extension ExportGuiXY: https://www.dropbox.com/s/wxf4swqv0e5g3 ... Y.zip?dl=0
Btw in the .inx file there is an id entry with a namespace link. I haven't changed that because I am modifying an existing extension, but do I have to change it to my own namespace or? I am new to extensions so not sure what to do/not to do here.
From my testing all paths x and y coordinates, as they would be shown in the GUI, will now be printed to the error dialog, regardless of the off coord values in the SVG. I have tested with a number of my other paths I have made weeks ago before I began trying to do this and they also give the correct results when I check them. So it seems to actually work! yay
So the whole idea of this is to avoid having to go through the tedium of checking each nodes x and y in the GUI and simply have the extension print a list of it. Paths must have straight line segments no curves etc and not loop.
1. Select the path and note the GUI x and y of the first node in the path. The first node in the path is the node that Inkscape considers as the "first" node, presumably(always?) the node that was first created in the path so you have to know which node begins the path.... Also first node coords must be integers, so no decimals. I use snapping to place the nodes to ensure this.
2. Flip the path.
3. Select path and select all nodes in path with ctrl-a and move them all at once so that the first node is at the same x and y as it was before the flip.
4. Run the exportGuiXY extension from the extension menu under Export and input the first node x and y you noted in 1, press apply. Extension prints to dialog the correct x and y coords as they would have been shown in the GUI.
An improvement would be to have the extension automatically calculate the flipped x,y of the svg (without actually flipping the path about the first node) to make it even easier for the user. Also since I am completely new to extensions and Python I expect the code I have added and modified could be optimized.
Issues: input dialog box does not close automatically on clicking Apply, must also click Close. Clicking Apply again instead of Close raises an error.
The most ideal thing would of course be to have an extension that could simply read the values directly of the X: and Y: boxes in the GUI. But I have found no way of doing that anywhere so I don't know if it is even possible...