Closed jumalakarhu closed 2 years ago
I can suggest two answers to this request:
svg_root
. Hence, you can can use inkex
and lxml
methods to remove all shape objects from the current document:for c in svg_root.iter():
if isinstance(c, inkex.ShapeElement) and not isinstance(c, inkex.Layer):
c.delete()
os.environ
in your script to read the recipient's name from an environment variable:
cx, cy = width/2, height/2
text('Merry Christmas,', (cx, cy/2), font_size='24pt',
font_family="'Zapf Chancery', cursive", text_anchor='middle',
fill='red')
try:
name = os.environ['RECIPIENT']
except KeyError:
name = 'Dude'
more_text(name, (cx, cy/2 + (24 + 2)*0.75*2))
style(stroke='none')
regular_polygon(3, (cx, cy + 75), 100, fill='#008000')
regular_polygon(3, (cx, cy), 100, fill='#008000')
rect((cx - 25, cy + 125), (cx + 25, cy + 200), fill='#784421')
Then run Simple Inkscape Scripting using a command like the following:
env RECIPIENT=jumalakarhu PYTHONPATH=/usr/share/inkscape/extensions:$PYTHONPATH ~/.config/inkscape/extensions/simple_inkscape_scripting/simple_inkscape_scripting.py --py-source=greeting-card.py --output=greeting-card-jumalakarhu.svg greeting-card-template.svg
in which your script is called greeting-card.py
, the output file is called greeting-card-jumalakarhu.svg
(which you should change per recipient), and greeting-card-template.svg
is an SVG image that contains everything that should stay the same from recipient to recipient (page dimensions, artwork, etc.).
Fantastic! Thanks
Is it possible within the script to create a new document or at least to clear canvas? What I would like to achieve is to create similar Seasons greeting cards with unique name of recipient.