Extention Collect images/Publish Zip
Hello,
I've been busy creating my first extention for inkscape which is also my first python script. Though it needs some work we use it allready and it's is quite usefull.
Its called "Publish Zip" and resides in the filters menu. It does the following:
- it copies all linked images to the current dir en modifies all links to be relative
- it creates a zip containing the document and the linked images.
The zip can be mailed and opened by someone else with all images correctly displayed.
You can find it here: http://sourceforge.net/tracker/index.php?func=detail&aid=1364270&gro...
known problems: - Document has to be saved first
- to create a correct svg-document in the zipfile pubzip has to be run, then the document has to be saved, then pubzip has to be run again.
- it fails with an ugly error when document is never saved before.
Unknown problems: - only tested on Linux/Debian PPC
To solve the known problems I've a question: Is there a possibility to give a "save doc" command from inside a python script to inkscape? This would fix all above problems. If someone has another solution to solve these problems please tell me.
Also another question: Is it possible to put an extention function in the File Menu next to e.g. "Save as"?
Regards, Pim Snel
On Wed, 2005-11-23 at 14:37 +0100, Pim Snel wrote:
I've been busy creating my first extention for inkscape which is also my first python script. Though it needs some work we use it allready and it's is quite usefull.
Very cool. This is an oft requested feature.
To solve the known problems I've a question: Is there a possibility to give a "save doc" command from inside a python script to inkscape? This would fix all above problems. If someone has another solution to solve these problems please tell me.
Also another question: Is it possible to put an extention function in the File Menu next to e.g. "Save as"?
Yes, most definitely. Actually, most of the extensions in use today are in the Open/Save dialogs, the fact that you didn't notice is a good thing :)
What you probably have in your .inx file now is an <effect> block, you'll want to replace that with an <output> block. Here is an example:
http://cvs.sourceforge.net/viewcvs.py/inkscape/inkscape/share/extensions/ai_...
I don't know off hand what other questions you might have, so please ask them!
Also, please post your work to the list or the patch tracker. I'm sure that some people will find it useful even in an uncompleted form.
--Ted
Op donderdag 24 november 2005 10:12, schreef Ted Gould:
Very cool. This is an oft requested feature.
Thanks.
To solve the known problems I've a question: Is there a possibility to give a "save doc" command from inside a python script to inkscape? This would fix all above problems. If someone has
another
solution to solve these problems please tell me.
Yes, most definitely. Actually, most of the extensions in use today are in the Open/Save dialogs, the fact that you didn't notice is a good thing :)
What you probably have in your .inx file now is an <effect> block, you'll want to replace that with an <output> block. Here is an example:
http://cvs.sourceforge.net/viewcvs.py/inkscape/inkscape/share/extensions/ai _output.inx?rev=1.3&view=markup
What I really would like it to put is next to "save as" instead of in the "save as", because the extention saves a copy in the zip and leaves the original document the current.
Maybe inkscape needs an export sub menu. It would really fit here.
I don't know off hand what other questions you might have, so please ask them!
Also, please post your work to the list or the patch tracker. I'm sure that some people will find it useful even in an uncompleted form.
Its in the patch tracker :)
--Ted
Pim
On Thu, 2005-11-24 at 11:45 +0100, Pim Snel wrote:
What I really would like it to put is next to "save as" instead of in the "save as", because the extention saves a copy in the zip and leaves the original document the current.
Maybe inkscape needs an export sub menu. It would really fit here.
Well, I really think this should be an output extension, just because it does something different than all the other effects. Effects tend to change the current document in some way, not create a file. The output extensions are specifically designed for creating a file. You wouldn't have your issues with needing to save first (for instance). Also, filename collisions would be handled.
But, if I can't convince you, there is a way to get an Effect listed in any menu, although it is a hack. And, it will still be listed in the effect menu also. If you edit the menu structure XML by adding in an entry, and for the verb ID you use the effect's extension id, it should show up in the menu.
--Ted
Hi,
I followed the advise and I seperated the earlier extension in two parts. One that resides in Effects and does the collection of all images to the documents current dir. The other resides in "save as" which save an zip archive incuding all images.
This makes the functionallity more logical and less problematic.
Download them here: http://facility.lingewoud.nl/hacks/
I only have one problem which seems to be a inkscape bug. After the effect is run the file is saved as a normal svg in stead of a ziparchive. You have to do "save as" again. I allready filed a bugreport at https://sourceforge.net/tracker/?group_id=93438&atid=604306
Next version of the "save as zip" extension will again collect the images itself.
Regards, Pim Snel
Pim Snel wrote:
I followed the advise and I seperated the earlier extension in two parts. One that resides in Effects and does the collection of all images to the documents current dir. The other resides in "save as" which save an zip archive incuding all images.
I haven't tried this extension yet, or even really read the code. But I don't see why there has to be all this complexity to avoid.
I only have one problem which seems to be a inkscape bug. After the effect is run the file is saved as a normal svg in stead of a ziparchive. You have to do "save as" again. I allready filed a bugreport at https://sourceforge.net/tracker/?group_id=93438&atid=604306
I'm gonna bet this is a problem with inkex.py or the use of it rather than inkscape. As designed inkex.py's output() spits the modified svg back to STDOUT. So what we need to do is either override output in your extension to do what inkscape expects for an output extension or modify inkex.py so that it has a method specific to output extensions. Sorry I didn't comment earlier. Let's get this sorted out. It is a much desired feature.
Aaron Spike
aaron@...749... wrote:
So what we need to do is either override output in your extension to do what inkscape expects for an output extension or modify inkex.py so that it has a method specific to output extensions.
By the way, does someone know offhand what Inkscape expects from an output extension? Does it expect the finished file on STDOUT?
Aaron Spike
Op dinsdag 29 november 2005 03:11, schreef aaron@...749...:
I haven't tried this extension yet, or even really read the code. But I don't see why there has to be all this complexity to avoid.
I think its slightlty difficult because the extension has to do two things, which normally are done at different times
1. manipulate current svg so it contains relative image-paths 2. save the manipulated doc in the archive.
To solve this, I want to let the extension manipulate the temp file which inkscape creates, so it can save the file itself after it has made his modifications.
I only have one problem which seems to be a inkscape bug. After the effect is run the file is saved as a normal svg in stead of a ziparchive. You have to do "save as" again. I allready filed a bugreport at https://sourceforge.net/tracker/?group_id=93438&atid=604306
I'm gonna bet this is a problem with inkex.py or the use of it rather than inkscape. As designed inkex.py's output() spits the modified svg back to STDOUT. So what we need to do is either override output in your extension to do what inkscape expects for an output extension or modify inkex.py so that it has a method specific to output extensions. Sorry I didn't comment earlier. Let's get this sorted out. It is a much desired feature.
The bug is not specific for the zip-extension. In my bugreport I give the example with the Connect the Dots effect and the .ps output. In this example you end up with a .ps-file which really is a plain svg-file.
Pim
Pim Snel wrote:
Op dinsdag 29 november 2005 03:11, schreef aaron@...749...:
I haven't tried this extension yet, or even really read the code. But I don't see why there has to be all this complexity to avoid.
I think its slightlty difficult because the extension has to do two things, which normally are done at different times
- manipulate current svg so it contains relative image-paths
- save the manipulated doc in the archive.
To solve this, I want to let the extension manipulate the temp file which inkscape creates, so it can save the file itself after it has made his modifications.
This should be easy if you override the default output() method of inkex.py to allow you to do what you need (eg. give it a function body of "pass"). Then you should be able to: 1. create a temporary directory in an OS independent way using the tempfile module. 2. copy all images to this directory 3. rename all paths in the in memory copy of the document 4. use python to save the file into the directory 5. zip the directory and give to inkscape
I only have one problem which seems to be a inkscape bug. After the effect is run the file is saved as a normal svg in stead of a ziparchive. You have to do "save as" again. I allready filed a bugreport at https://sourceforge.net/tracker/?group_id=93438&atid=604306
I'm gonna bet this is a problem with inkex.py or the use of it rather than inkscape. As designed inkex.py's output() spits the modified svg back to STDOUT. So what we need to do is either override output in your extension to do what inkscape expects for an output extension or modify inkex.py so that it has a method specific to output extensions. Sorry I didn't comment earlier. Let's get this sorted out. It is a much desired feature.
The bug is not specific for the zip-extension. In my bugreport I give the example with the Connect the Dots effect and the .ps output. In this example you end up with a .ps-file which really is a plain svg-file.
Ok, weird. This sounds like one very good argument for why we shouldn't "save" to filetypes other than SVG. PS output should be an export and certainly shouldn't change the filetype of the working document.
Aaron Spike
Op dinsdag 29 november 2005 14:08, schreef aaron@...749...:
This should be easy if you override the default output() method of inkex.py to allow you to do what you need (eg. give it a function body of "pass"). Then you should be able to:
- create a temporary directory in an OS independent way using the
tempfile module. 2. copy all images to this directory 3. rename all paths in the in memory copy of the document 4. use python to save the file into the directory 5. zip the directory and give to inkscape
The plugin now just saves the zip. It doesn't return (give) it to inkscape. Is it necessary to return it?
I'll try above in the next version.
The bug is not specific for the zip-extension. In my bugreport I give the example with the Connect the Dots effect and the .ps output. In this example you end up with a .ps-file which really is a plain svg-file.
Ok, weird. This sounds like one very good argument for why we shouldn't "save" to filetypes other than SVG. PS output should be an export and certainly shouldn't change the filetype of the working document.
I agree on this. Most programs handle other file formats this way.
Pim
Pim Snel wrote:
The plugin now just saves the zip. It doesn't return (give) it to inkscape. Is it necessary to return it?
I don't know. I was hoping Ted would give us the answer. But the answer may be somewhere around here: http://www.inkscape.org/doc/doxygen/html/script_8cpp-source.php#l00500
Aaron Spike
On Tue, 29 Nov 2005, Pim Snel wrote:
Date: Tue, 29 Nov 2005 14:28:29 +0100 From: Pim Snel <pim@...810...> To: inkscape-devel@lists.sourceforge.net Subject: Re: [Inkscape-devel] Collect images and Save as Zip, was publish zip
Op dinsdag 29 november 2005 14:08, schreef aaron@...749...:
This should be easy if you override the default output() method of inkex.py to allow you to do what you need (eg. give it a function body of "pass"). Then you should be able to:
- create a temporary directory in an OS independent way using the
tempfile module. 2. copy all images to this directory 3. rename all paths in the in memory copy of the document 4. use python to save the file into the directory 5. zip the directory and give to inkscape
The plugin now just saves the zip. It doesn't return (give) it to inkscape. Is it necessary to return it?
Would be nice but I wouldn't say it was necessary given the intention is to package this all up to be sent on somewhere else rather than keep working on it.
This does sound like a lot of work, can the code for creating inkjar files not be easily reused and included natively in Inkscape to help save on the amount of work which needs to be implemented as an extension?
- Alan
Op woensdag 30 november 2005 16:34, schreef Alan Horkan: on@...749...:
This should be easy if you override the default output() method of inkex.py to allow you to do what you need (eg. give it a function body of "pass"). Then you should be able to:
- create a temporary directory in an OS independent way using the
tempfile module. 2. copy all images to this directory 3. rename all paths in the in memory copy of the document 4. use python to save the file into the directory 5. zip the directory and give to inkscape
The plugin now just saves the zip. It doesn't return (give) it to inkscape. Is it necessary to return it?
Would be nice but I wouldn't say it was necessary given the intention is to package this all up to be sent on somewhere else rather than keep working on it.
This does sound like a lot of work,
I think it's not so hard.
can the code for creating inkjar files not be easily reused and included natively in Inkscape to help save on the amount of work which needs to be implemented as an extension?
Can you tell me how to create inkjar files, I don't know where to find this in inkscape. Doesn't the jar functionality only work for inkview?
I investigated inkview a little and it seems that it can only open jars which have no images packed. I don't know this for sure.
By the way when the concept is implemented for zip I think its easy to reimplement it working with jars.
Pim
Op dinsdag 29 november 2005 14:08, schreef aaron@...749...:
This should be easy if you override the default output() method of inkex.py to allow you to do what you need (eg. give it a function body of "pass"). Then you should be able to:
- create a temporary directory in an OS independent way using the
tempfile module. 2. copy all images to this directory 3. rename all paths in the in memory copy of the document 4. use python to save the file into the directory 5. zip the directory and give to inkscape
Yes, did it. It now completely works as it should.
It creates a zip with all pictures and the svg doc with correct image paths. It uses a temp directory for collecting everything and it removes the temp dir after the zip is created.
Download it at: http://facility.lingewoud.nl/hacks/inkscape_save_as_zip/
Thanks for the advise Aaron.
Pim
Ps: please test the extension on other platform. I created it on Linux PPC
Pim Snel wrote:
Thanks for the advise Aaron.
Thanks for coding this!
Ps: please test the extension on other platform. I created it on Linux PPC
Works great on WinXP! One little quirk I noticed is that if an image is included in the svg twice it gets into the archive twice. This isn't fatal because it still works, but could increase the size significantly. NSS can be removed from the script because I moved it to inkex. I can do this for you before I commit it. Does anyone think it would be useful to save the files in a directory inside of the archive so that they stick together when unarchiving? And what about an identical extension for plain SVG, since people have expressed concerns about distributing files with local paths?
So I think this is good enough to get into CVS immediately.
Thanks.
Aaron Spike
Op donderdag 1 december 2005 03:14, schreef aaron@...749...:
Works great on WinXP! One little quirk I noticed is that if an image is included in the svg twice it gets into the archive twice. This isn't fatal because it still works, but could increase the size significantly. NSS can be removed from the script because I moved it to inkex. I can do this for you before I commit it. Does anyone think it would be useful to save the files in a directory inside of the archive so that they stick together when unarchiving? And what about an identical extension for plain SVG, since people have expressed concerns about distributing files with local paths?
Please make the improvements you think are needed. If we had an open zip extension we are complete.
Pim
Pim Snel wrote:
Op donderdag 1 december 2005 03:14, schreef aaron@...749...:
Works great on WinXP! One little quirk I noticed is that if an image is included in the svg twice it gets into the archive twice. This isn't fatal because it still works, but could increase the size significantly. NSS can be removed from the script because I moved it to inkex. I can do this for you before I commit it. Does anyone think it would be useful to save the files in a directory inside of the archive so that they stick together when unarchiving? And what about an identical extension for plain SVG, since people have expressed concerns about distributing files with local paths?
Please make the improvements you think are needed. If we had an open zip extension we are complete.
Pim
Has anyone looked at the Inkjar code and how Inkview uses it? It has been in the code base for over a year, and seems to be very similar to other jar formats, like for Java or OpenDocument. Basically a zip of file + resources and a manifest. It would be great if Inkview could read the files that Inkscape makes.
src/inkjar/jar/cpp src/inkview.cpp
Also, if we are maybe (slowly) moving toward using URI's instead of file names, then there would be the JAR URL spec:
http://java.sun.com/j2se/1.5.0/docs/guide/jar/index.html (ignore the 'Java' part, it's a general-purpose format now)
...that we could use to specify URIs of resources within zips, the same as any other files. And xlink: paths would follow the rules for absolute or relative URIs.
bob
Has anyone looked at the Inkjar code and how Inkview uses it? It has been in the code base for over a year, and seems to be very similar to other jar formats, like for Java or OpenDocument. Basically a zip of file + resources and a manifest. It would be great if Inkview could read the files that Inkscape makes.
src/inkjar/jar/cpp src/inkview.cpp
Also, if we are maybe (slowly) moving toward using URI's instead of file names, then there would be the JAR URL spec:
http://java.sun.com/j2se/1.5.0/docs/guide/jar/index.html (ignore the 'Java' part, it's a general-purpose format now)
...that we could use to specify URIs of resources within zips, the same as any other files. And xlink: paths would follow the rules for absolute or relative URIs.
bob
I tried to investigate it but there is very little documentation this and it seems not to be able to handle images at the moment, but maybe I just don't understand how to make correct inkjars.
Pim
participants (5)
-
unknown@example.com
-
Alan Horkan
-
Bob Jamison
-
Pim Snel
-
Ted Gould