(Hi to all. Only my 2nd Post...)... I've been using a coding Extension called 'ExportXY', (latest version). It does it's job WELL, but uses 'TAB' separated Values, with a simple LineFeed after each X/Y pair... Here is the relevant section of the Python coding.... https://i.imgur.com/GFSzbsY.png The relevant Line being.... https://i.imgur.com/SDrfvIO.png I successfully changed that line, to.... https://i.imgur.com/W4ji5a3.png Where the TABS were replaced with a 'Comma', and the LineFeed replaced with a 'Comma' & a LineFeed.... That all worked!!, and is good!, but here-in lies my main question!!.... (I'm used to Javascript, but not with Python). The NEXT step of my 'coding', (for use in an unrelated software package), is to convert all that to a 'JSON' format.(My problem). In relation to the 1st image/coding above,.... The requirements being that the FIRST line of the resultant data, just contains the parameter names, 'X,Y' on it's own line..., And that the LAST line of the now CSV data, does NOT have a final 'Comma' at the very end!!!.... So what I need to learn, is where, just before the main data writing Loop, can I write the initial First line being... 'X,Y' ?? And how to NOT show the last 'Comma', at the very end!!! I'm sure I'm asking a lot, but I'm trying to get a handle on the 'Python'....
To help explain what I MEAN, here is an example of the resultant Data, that I'm trying to achieve, using my 'Modified' 'ExportXY'...... https://i.imgur.com/BDYxR5J.png (Ignore the 'actual Data shown there!!!).... And here is a typical representation as the equivalent 'JSON' data, that my specialized software uses!!!... (Again... Ignore the actual 'Data').... https://i.imgur.com/eICyDtU.png
Please forgive me, as I'm old!!! hahahaha..... π
IGNORE THE REPLY JUST ABOVE.... SEEMS TO WORK NOW !!!!....
Sorry about the delay here!!! I've already partially edited the Inkscape Extensions | Export files here.... (And sorry about the crappy Image links in my first post!!!!)
class TemplateEffect(inkex.Effect): def __init__(self): inkex.Effect.__init__(self) def effect(self): for node in self.selected.items(): output_all = output_nodes = "" for id, node in self.selected.items(): if node.tag == inkex.addNS('path','svg'): output_all += "" output_nodes += "" node.apply_transform() d = node.get('d') p = paths.CubicSuperPath(d) for subpath in p: for csp in subpath: # The line below has been modified, to make 'comma' delimited parts!! # output_nodes += str(csp[1][0]) + "\t" + str(csp[1][1]) + "\n" output_nodes += str(csp[1][0]) + "," + str(csp[1][1]) + ",\n" sys.stderr.write(output_nodes) TemplateEffect().run() sys.exit(0) #helps to keep the selection
Note near the end of the Python file, where I've changed the output to 'comma' Delimits, already. (And works fine!). (Here's a copy of my last post paragraph though...) The requirements being that the FIRST line of the resultant data, to just contain the parameter names, 'X,Y' on it's own line..., And that the LAST line of the now CSV data, does NOT have a final 'Comma' at the very end!!!.... So what I need to learn, is where, just before the main data writing Loop, can I write the initial First line being... 'X,Y' ?? And how to NOT show the last 'Comma', at the very end!!! I'm sure I'm asking a lot, but I'm trying to get a handle on the 'Python'....
Don't bother with my original mention about conversion to 'JSON' here. That's a different module...
If you are going to write your own extension I would recommend looking at something like this: https://gitlab.com/kaalleen/inspect-nodes (which works on nodes selected by the node tool) as a base before you spend a lot of time editing the old one.
@inklinea . . . Thanks mate!!!, those mods worked well, and I actually understood them !! hahaha... Mind you, in your first mod, (output_all = output_nodes = "X,Y,\n"), I had to leave out the 'comma' after the 'Y', for JSON conversion later. Here's a partial image of the before & after, using.... https://csvjson.com/csv2json site, with the Inkscape Generated Points/Nodes now....
@inklinea . . . Re: Your last suggestion to me, at the bottom, about using 'inspect-nodes', as a basis, looks nice, but not fitting my needs at the moment. The original Extension above, (edited by myself & you), pretty much does all I want/need right now. π With the exception of continuing it some day!, to do the 'JSON' conversion as well as an option!!, so I don't have to rely on the On-Line Converter Site, that I mentioned above!! hahaha.... π Out of interest, for you & others, I'm mainly using all the above, for a now 'on-Line' App called... "Physion". https://app.physion.net/ Although that App can create 'Polygons', including basic 'Gears', I'm creating Files of more Complex Polygons, to import data via 'JSON', which that App requires for all Polygon Data.... Thank You for your great help, so far!!! Glenn. π
NOTE: Some aspects of the 'Physion' App mentioned above, is having Temp problems with 'Firefox' Browser!!! Use any other browser for now...
(Hi to all. Only my 2nd Post...)... I've been using a coding Extension called 'ExportXY', (latest version). It does it's job WELL, but uses
'TAB' separated Values, with a simple LineFeed after each X/Y pair... Here is the relevant section of the Python coding....
https://i.imgur.com/GFSzbsY.png
The relevant Line being....
https://i.imgur.com/SDrfvIO.png
I successfully changed that line, to....
https://i.imgur.com/W4ji5a3.png
Where the TABS were replaced with a 'Comma', and the LineFeed replaced with a 'Comma' & a LineFeed....
That all worked!!, and is good!, but here-in lies my main question!!.... (I'm used to Javascript, but not with Python).
The NEXT step of my 'coding', (for use in an unrelated software package), is to convert all that to a 'JSON' format.(My problem).
In relation to the 1st image/coding above,....
The requirements being that the FIRST line of the resultant data, just contains the parameter names, 'X,Y' on it's own line...,
And that the LAST line of the now CSV data, does NOT have a final 'Comma' at the very end!!!....
So what I need to learn, is where, just before the main data writing Loop, can I write the initial First line being... 'X,Y' ??
And how to NOT show the last 'Comma', at the very end!!! I'm sure I'm asking a lot, but I'm trying to get a handle on the 'Python'....
To help explain what I MEAN, here is an example of the resultant Data, that I'm trying to achieve, using my 'Modified' 'ExportXY'......
https://i.imgur.com/BDYxR5J.png
(Ignore the 'actual Data shown there!!!)....
And here is a typical representation as the equivalent 'JSON' data, that my specialized software uses!!!... (Again... Ignore the actual 'Data')....
https://i.imgur.com/eICyDtU.png
Please forgive me, as I'm old!!! hahahaha..... π
Can you post a link to the extension ?
Just testing a 'reply' as something is going wrong......
IGNORE THE REPLY JUST ABOVE.... SEEMS TO WORK NOW !!!!....
Sorry about the delay here!!! I've already partially edited the Inkscape Extensions | Export files here....
(And sorry about the crappy Image links in my first post!!!!)
The ExportXY-CSV.inx is shown below...
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<_name>Export XY-CSV</_name>
<id>org.simarilius.filter.ExportXY-CSV</id>
<dependency type="executable" location="extensions">ExportXY-CSV.py</dependency>
<dependency type="executable" location="extensions">inkex.py</dependency>
<effect needs-live-preview="false">
<object-type>all</object-type>
<effects-menu>
<submenu _name="Export"/>
</effects-menu>
</effect>
<script>
<command reldir="extensions" interpreter="python">ExportXY-CSV.py</command>
</script>
</inkscape-extension>
And the ExportXY-CSV.py file is shown below....
import inkex
import sys
from inkex import paths
from inkex import transforms
def warn(*args, **kwargs):
pass
import warnings
warnings.warn = warn
class TemplateEffect(inkex.Effect):
def __init__(self):
inkex.Effect.__init__(self)
def effect(self):
for node in self.selected.items():
output_all = output_nodes = ""
for id, node in self.selected.items():
if node.tag == inkex.addNS('path','svg'):
output_all += ""
output_nodes += ""
node.apply_transform()
d = node.get('d')
p = paths.CubicSuperPath(d)
for subpath in p:
for csp in subpath:
# The line below has been modified, to make 'comma' delimited parts!!
# output_nodes += str(csp[1][0]) + "\t" + str(csp[1][1]) + "\n"
output_nodes += str(csp[1][0]) + "," + str(csp[1][1]) + ",\n"
sys.stderr.write(output_nodes)
TemplateEffect().run()
sys.exit(0) #helps to keep the selection
Note near the end of the Python file, where I've changed the output to 'comma' Delimits, already. (And works fine!).
(Here's a copy of my last post paragraph though...)
The requirements being that the FIRST line of the resultant data, to just contain the parameter names, 'X,Y' on it's own line...,
And that the LAST line of the now CSV data, does NOT have a final 'Comma' at the very end!!!....
So what I need to learn, is where, just before the main data writing Loop, can I write the initial First line being... 'X,Y' ??
And how to NOT show the last 'Comma', at the very end!!! I'm sure I'm asking a lot, but I'm trying to get a handle on the 'Python'....
Don't bother with my original mention about conversion to 'JSON' here. That's a different module...
This is quite and old extension.
Replace
output_all = output_nodes = ""
output_all = output_nodes = "X,Y,\n"
At the end change this:
sys.stderr.write(output_nodes)
to this:
# Use string slicing to remove characters from end.
output_nodes = output_nodes[:-2]
sys.stderr.write(output_nodes)
In the .inx (If you are using Inkscape 1.3)
Probaly need to remove (or comment out) the below:
<dependency type="executable" location="extensions">ExportXY-CSV.py</dependency>
<dependency type="executable" location="extensions">inkex.py</dependency>
---------------------------------
If you are going to write your own extension I would recommend looking at something like this: https://gitlab.com/kaalleen/inspect-nodes (which works on nodes selected by the node tool) as a base before you spend a lot of time editing the old one.
Thank you my friend.... I will work on that, and get back to you!!! π
@inklinea . . . Thanks mate!!!, those mods worked well, and I actually understood them !! hahaha...
Mind you, in your first mod, (output_all = output_nodes = "X,Y,\n"), I had to leave out the 'comma' after the 'Y', for JSON conversion later.
Here's a partial image of the before & after, using.... https://csvjson.com/csv2json site, with the Inkscape Generated Points/Nodes now....
@inklinea . . . Re: Your last suggestion to me, at the bottom, about using 'inspect-nodes', as a basis, looks nice, but not fitting
my needs at the moment. The original Extension above, (edited by myself & you), pretty much does all I want/need right now. π
With the exception of continuing it some day!, to do the 'JSON' conversion as well as an option!!, so I don't have to rely on the
On-Line Converter Site, that I mentioned above!! hahaha.... π
Out of interest, for you & others, I'm mainly using all the above, for a now 'on-Line' App called... "Physion". https://app.physion.net/
Although that App can create 'Polygons', including basic 'Gears', I'm creating Files of more Complex Polygons, to import data via 'JSON',
which that App requires for all Polygon Data.... Thank You for your great help, so far!!! Glenn. π
NOTE: Some aspects of the 'Physion' App mentioned above, is having Temp problems with 'Firefox' Browser!!! Use any other browser for now...