I'm currently using this great extension (yes, it does work fine for me on both the development and stable versions, on a Windows XP machine). It's great for exporting a large amount of icons from a single file - I used to have to export from inkscape to photoshop to break a single file into slices, but now I can skip that, which is a great help.
Now the way I work with it, is like this: I'm creating a grid of icons on a single file. So, I open a new layer and name it "slices". On it I draw 16x16 pixel rectangles and give them appropriate icon names. now on the layers dialog I lock this layer and change its opacity to 0%, and I'm free to draw anything I want on a layer above that. Just before export I group all the stuff on the top layer, so when I run the extension I get PNG files for all my icons plus one large file with all of them at once, which I can delete.
So it's all well but I was wondering if there was any way I could edit the python script so it would only look for objects on a single layer named "slices". I'm not looking into any fancy change in dialog, I was just wondering if a quick hack of the python script could do that. I'm not a programmer, but I do have some background in scripting, so I tried to look a the script and the correct place seems to be the for loop at the end, but I'll be damned if I know what to put in there to make it do what I want.
So, if anyone can help me and it's not too much of a bother, I'd be really hankful!
Not sure why the subject line was trimmed. It should have been: help with the "export groups to PNG" extension.
So, if anyone can help me and it's not too much of a bother, I'd be really hankful!
Well, I have never hacked python in Inkscape before, and the XML is very confusing to me, but I'll spend some time on it -- so far I would say it looks hopeful.
I am sure a boffin will zap in and help you before I even figure-out how it works!
/d
Well, thanks for the effort anyway man!
Okay -- I have something. (BTW I can't reach you on your hotmail email for some reason)
I changed the g2png.py code -- hacking like a blind monkey without savvy It will now save ALL groups on a named layer (defaults to 'slices') out to a single PNG. I called it lg2png cos it's "Layer of Groups to Png"
I re-read your OP and I'm not really sure what you want it to do; I hope this one does it but, if not, you can use this new script along with the original to get some idea.
How to install: (I assume Linux, but Windows should be similar) 1. Copy the attached 2 files into : /usr/share/inkscape/extensions (I assume that's standard, check first). You will need to sudo copy them. 2. Restart Inkscape. 3. Done. 4. Test ( I haven't really tested it much) Good luck, HTH, I gotta get on with other stuff now.
/d PS - If the attachments don't get through to the list, please let me know where to send them.
Donn <donn.ingle@...125...> writes:
Well, thanks for the effort anyway man!
Okay -- I have something. (BTW I can't reach you on your hotmail email for some reason)
I changed the g2png.py code -- hacking like a blind monkey without savvy It will now save ALL groups on a named layer (defaults to 'slices') out to a single PNG. I called it lg2png cos it's "Layer of Groups to Png"
I re-read your OP and I'm not really sure what you want it to do; I hope this one does it but, if not, you can use this new script along with the original to get some idea.
Thanks again for the effort, and sorry to have bothered you. what I wanted was for the script to export a number of PNG files from that layer, not just a large single one. So, sorry I made you work for nothing :( I think maybe I'll try to contact the guy who wrote the extension.
You can do this easily with a simple adjustment to the xpath. Give me a moment to look at it and I'll get back to you. :-)
(XPath is really quite fun, you may want to study it some yourself. :-) )
Aaron Spike
You can do this easily with a simple adjustment to the xpath. Give me a moment to look at it and I'll get back to you. :-) (XPath is really quite fun, you may want to study it some yourself. :-) )
I spent a long time today on that xpath stuff. I got some online resources, but the complexity is really in grokking the Inkscape svg stuff.
Is there anything online (I could not find it in the wiki search) that would clarify SVG + xpath for dumbass xml newbz like me?
For example I could not figure out how to extract all the nodes with name='g' that were under @inkscape:label="slices". That colon just confused things no end.
/d
Thanks again for the effort, and sorry to have bothered you. what I wanted was for the script to export a number of PNG files from that layer, not just a large single one. So, sorry I made you work for nothing :( I think maybe I'll try to contact the guy who wrote the extension.
Ah right, would you send me the script when you get it working? I'd like to see what it *should* look like!
/d
Thanks again for the effort, and sorry to have bothered you. what I wanted was for the script to export a number of PNG files from that layer, not just a large single one. So, sorry I made you work for nothing :( I think maybe I'll try to contact the guy who wrote the extension.
Here's a new version created by sheer damage to g2png.py
You should make a backup of g2png.py, but this one simply remarks out the code so it's easy enough to revert. The tick box in the dialog makes no difference in this version of the script.
hth, and thanks to Aaron Spike /d
Donn <donn.ingle@...125...> writes:
You should make a backup of g2png.py, but this one simply remarks out the code so it's easy enough to revert. The tick box in the dialog makes no difference in this version of the script.
hth, and thanks to Aaron Spike
Thank you so much Donn and Aaron! that worked wonderfully.
Ok, yes, you can hack this quite simply by changing:
if self.options.layers: path = "/svg/*[name()='g' or @style][@id]" else: path = "/svg/g/*[name()='g' or @style][@id]"
to:
path = "/svg/g[@id='slices']/*"
I know everyone will scream cries of userunfriendlyness but, wow, xpath is useful and I think it would be fun to let the user choose what to export via xpath. Maybe we could create a graphical language for xpath.
Aaron Spike
Donn wrote:
path = "/svg/g[@id='slices']/*"
Now that is just confusing... When I look in the xml viewer the layer name is in an attribute called "inkscape:label", howcome @id does the job?
Oh, oops. You're right that doesn't work. But an xpath like this gets you something appropriate and specific:
path = "/svg/g[@inkscape:groupmode='layer' and @inkscape:label='slices']/*"
And the reason why that didn't work when you tried it is xml namespaces. If you'd like me to try to give a more complete explanation I could try but it will likely be clearer if you look up "xmlns". The solution is to inform the Evaluate method of the namespace context for the document you are working with. With inkex.py we can do this simple by adding "context=self.ctx" to the call as below:
inkex.xml.xpath.Evaluate(path,self.document,context=self.ctx)
Didn't mean to mislead you the first time. I named my test layer "layer2". A very bad choice. :-)
Aaron Spike
path = "/svg/g[@inkscape:groupmode='layer' and @inkscape:label='slices']/*"
inkex.xml.xpath.Evaluate(path,self.document,context=self.ctx)
Thanks -- with those changes it works. Sure was simpler than my solution, but I have never seen xpath before today. Looks like there's a lot to learn.
I won't trouble you for an explanation here -- I'd rather you write a tutorial on the wiki for all newbz like me :) Pretty please.
Oh, is there an easy way (under Linux) to see the xml and the result of an xpath Evaluate call? A way to see what results? I have this feeling the xpath path string is a little like SQL in the way it returns a sub set...
I'll put the script together for Michael Grosberg again.
/d
On Feb 8, 2007, at 8:24 AM, Donn wrote:
Oh, is there an easy way (under Linux) to see the xml and the result of an xpath Evaluate call? A way to see what results? I have this feeling the xpath path string is a little like SQL in the way it returns a sub set...
That depends on exactly how much of things you want to get.
The most generic approach is to have a stand-alone XSLT file. Just feed your .svg and .xsl to the xsltproc command and you'll see the result spew out.
On Thu, Feb 08, 2007 at 09:15:33AM -0600, Aaron Spike wrote:
Ok, yes, you can hack this quite simply by changing:
if self.options.layers: path = "/svg/*[name()='g' or @style][@id]" else: path = "/svg/g/*[name()='g' or @style][@id]"
to:
path = "/svg/g[@id='slices']/*"
I know everyone will scream cries of userunfriendlyness but, wow, xpath is useful and I think it would be fun to let the user choose what to export via xpath. Maybe we could create a graphical language for xpath.
Ooh, a graphical language for xpath would be sweet. :-)
Bryce
participants (5)
-
Aaron Spike
-
Bryce Harrington
-
Donn
-
Jon A. Cruz
-
Michael Grosberg