Simple Inkscape Scripting v4.0.0
This is a major new release of Simple Inkscape Scripting. It includes two changes that break existing code but that provide improved functionality:
Change #1: width
and height
are no longer defined.
Replacement: Use canvas.width
and canvas.height
.
Reason: canvas.width
and canvas.height
not only are readable but also are writable, which is not achievable in Python with top-level variables.
Change #2: Group objects (as returned by group
or layer
) no longer define an add
method.
Replacement: Use append
for a single addition or extend
for a list of additions.
Reason: Group objects now honor a rich set of standard list operations (append
, extend
, pop
, len
, etc.).
In addition to the above and the usual sorts of bug fixes, Simple Inkscape Scripting v4.0.0 provides a long list of new features:
- The
image
function can embed SVG files, not just PNG and JPEG files, as images. - An
objects_from_svg_file
function merges SVG objects from another document into the current document. - The
ungroup
method returns a list of objects that were released from the group. - The
clip_path
andmask
functions accept a list of objects in addition to a single object. - Scripts can accept command-line arguments, provided via the
user_args
variable. - The Simple Inkscape Scripting extension itself (an
inkex.extensions.EffectExtension
object) is accessible asextension
. - Path objects support
translate_path
,rotate_path
,scale_path
, andskew_path
methods, which modify the path's control points themselves. - An
unremove
method re-adds to the document an object that was removed withremove
. - The
save_file
function saves the current document to an SVG file. - Two Simple Inkscape Scripting objects are considered equal if they share an underlying
inkex
object. - The Simple Inkscape Scripting dialog box lets the user specify the input-file encoding (currently system-default, UTF-8, UTF-16, or Windows-1252).
- The
font_family
style attribute accepts not only a single string but also a list of strings. Hence,font_family='"New Century Schoolbook", "Times New Roman", serif'
can be expressed more naturally asfont_family=['New Century Schoolbook', 'Times New Roman', 'serif']
. - A new
canvas
object supports querying and modifying the canvas's viewport (physical size) and viewbox (coordinate system). - Multi-page documents can be created in Inkscape 1.2+ using the
page
command. - The
all_pages
function returns a list of all pages in the document. - An
inkex.colors.Color
can be used directly in a style attribute (typicallyfill
andstroke
). - The
randcolor
function returns a random color. Color channels optionally can be constrained to particular values.
See the Simple Inkscape Scripting commit log for details of all of the above.