I created some objects that I intend to use in my future inkscape documents. To make these objects neatly organized and easy to use I transformed them in a symbol library. Now my question:
With these symbols I created many documents. If one day I modify the symbols, how do I update the documents that use them? Is there any automatic way? If not, is there a manual way? How?
[...] Does changing a symbol in a library cause all the symbols referring to it from other documents to change as well? No, because when you use a symbol from another symbol library in a document, it gets copied to this document, in its defs XML element.
Inkscape symbols are a special case of SVG clones. Parent objects are defined in the <svg:defs> element and so aren't rendered on the canvas. Select a symbol in your drawing and open the XML Editor [shift+ctrl+x]. The [xlink:href] attribute identifies the name of the parent. Use the Find/Replace dialog [shift+ctrl+F] [ctrl+F] to link a different parent.
@Paddy_CAD I made a test. I create square and a circle I create a clone of the square Using the XML editor I changed the xlink:href of the cloned square referencing the circle The cloned square has been transformed in a cloned circle
I created some objects that I intend to use in my future inkscape documents. To make these objects neatly organized and easy to use I transformed them in a symbol library. Now my question:
With these symbols I created many documents. If one day I modify the symbols, how do I update the documents that use them? Is there any automatic way? If not, is there a manual way? How?
Thanks!
If the symbols have unique ids, which you have a record of then it can be done by:
Copying the files. Creating a new master file with the altered symbols in.
Then search each file for the symbol entry and replace with matching id in the modified master file.
However would require a bit of scripting.
@inklinea I have found this:
If that's correct, I think I should:
- find in all the documents the ID and corresponding defs of each of my symbol
- replace the old definition with the new one
What do you think?
Correct, I think that if you know how to use python:
You could possibly use
from lxml import etree
master_svg = etree.parse(master_svg_filepath)
target_svg = etree.parse(target_svg_filepath)
then use xpath to find the relevant symbols in each
then I think something like current.symbol.getparent()
in each, then replace in the target svg.
the tostring().decode('utf-8'), and save the string to another file.
Maybe :)
However there is a loadsvg function in inkex ( the Inkscape extension system )
and in that case would be a lot easier - an example of loadsvg is in the built in extensions bundled with Inkscape - template_seamless_pattern.py
Thanks a lot for your help and the detailed explanation @inklinea. I was interested in understanding the principle. I hope I will not need to do it :)
Inkscape symbols are a special case of SVG clones. Parent objects are defined in the <svg:defs> element and so aren't rendered on the canvas. Select a symbol in your drawing and open the XML Editor [shift+ctrl+x]. The [xlink:href] attribute identifies the name of the parent. Use the Find/Replace dialog
[shift+ctrl+F][ctrl+F] to link a different parent.Find: #Parent_Name_1
Replace: #Parent_Name_2
Search In: Properties
Properties: Attribute value
Object Types: Clones
@Paddy_CAD thank you, clear!!!
P.S. In my Inkscape 1.1 Find/Replace is CTRL F
@Paddy_CAD I made a test.
Thanks!
I had an attempt at making an automated version of this to replace symbols across multiple files.
I consider it to be a failed extension, due to the problem with transforms :(
However, it does seem to work in Inkscape 1.2rc ?
I'm not 100% sure why. Just thought I would post it for anyone who is interested.
https://gitlab.com/inklinea/symbol-replace
This is a standard feature: relink clones.
Doing similar with symbols is not so simple, unfortunately.