I am currently working with Python scripts and Inkscape and there seems to be an issue with the filters. Filters do not get applied unless the xml/svg code already has a tag for it, so files that haven't had filters applied to them before can not apply filters to them later. (Via scripting) I need to be able to apply the filters through scripting alone. So how do I make it so that I can script filters into my image? There is also a problem that the filters' IDs are randomized, so how would I be able to to use the same filter in different windows, or even just twice. (As they appear to be randomized every single time you use a filter)
I am looking at the xml code by opening the svg file through a word editor, not through the xml code editor in Inkscape. Also I am using the trunk version of Inkscape. (I don't know if that's necessary to know)
Filters and Python Scripts
Re: Filters and Python Scripts
SpaceJelly wrote:I am currently working with Python scripts and Inkscape
What are you trying to do ? Writing an extension for inkscape ?
SpaceJelly wrote:Filters do not get applied unless the xml/svg code already has a tag for it
add a style="filter:url(#unique_id_of_filter)" to objects (g, rect, path...) you want to add a filter
SpaceJelly wrote:so files that haven't had filters applied to them before can not apply filters to them later.
what do you mean by "files" ? You do not apply filter on "file" (but a svg file can contain 0 or more filter definitions)
SpaceJelly wrote:(Via scripting) I need to be able to apply the filters through scripting alone.
So how do I make it so that I can script filters into my image?
There is also a problem that the filters' IDs are randomized,
In inkscape you can duplicate a filter to work on it but to handle it easily (internally) you need a unique id that's hy inkscape gives a "random" id to every new filter that is added.
You can look at the genuine definitions of filters in the file /usr/share/inkscape/filters/filters.svg (that' on linux ; on windows search inkscape dir for "filters.svg")
so, to apply a filter on a "file" :
open the svg (as xml)
if there's no defs section, add one
insert the filter definition in the defs section
if you only need 1 filter you can hardcode it in your code
You can also use "filters.svg" (open as xml; search for the filter you want (eg //filter@inkscape:label='Matte Jelly')
select the object on which you want to apply filter and add a style="filter:url(#f002)" (in my version of filters.svg the filter 'Matte Jelly' as an id of 'f002')
SpaceJelly wrote:so how would I be able to to use the same filter in different windows
What do you mean by "windows" ?
-
SpaceJelly
- Posts: 2
- Joined: Tue Jul 10, 2012 6:57 am
Re: Filters and Python Scripts
I am testing the Inkscape dbus commands and how well they work with scripting. This ties into a larger goal of making inkscape scriptable through other languages, such as scheme.
A problem I have been running into is that the dbus commands, merge_css and document_merge_css are unable to apply the filter, because the filter tag does not exist in svg files unless a filter is applied through the inkscape interface. So the issue is that I cannot apply filters through scripting. I was able to apply the code by changing the svg code, but I'm not sure how this can help with the scripting. The only case where I was able to apply a filter through script was when I imported an image with the filter I wanted, and then applied the filter to another shape. It does not work for other filters and it obviously can't really help me as I need to be able to apply filters through script alone. I tried importing the filters.svg file to see if it would work but it ended up crashing Inkscape.
When running the python scripts, I open a new inkscape window everytime I run the program. So how do I make sure the filter is constant even though the id changes as I keep opening new inkscape windows?
A problem I have been running into is that the dbus commands, merge_css and document_merge_css are unable to apply the filter, because the filter tag does not exist in svg files unless a filter is applied through the inkscape interface. So the issue is that I cannot apply filters through scripting. I was able to apply the code by changing the svg code, but I'm not sure how this can help with the scripting. The only case where I was able to apply a filter through script was when I imported an image with the filter I wanted, and then applied the filter to another shape. It does not work for other filters and it obviously can't really help me as I need to be able to apply filters through script alone. I tried importing the filters.svg file to see if it would work but it ended up crashing Inkscape.
When running the python scripts, I open a new inkscape window everytime I run the program. So how do I make sure the filter is constant even though the id changes as I keep opening new inkscape windows?