Releases: spakin/SimpInkScr
Simple Inkscape Scripting v5.3.0
This release of Simple Inkscape Scripting introduces a few handy features:
- All Simple Inkscape Scripting objects define a
get_idmethod that returns the SVG ID of the underlyinginkexobject. - An
alignfunction provides a flexible means of aligning objects à la Inkscape's Object → Align and Distribute… dialog box. - The Simple Inkscape Scripting dialog box includes an "Ignore missing/broken Python packages" checkbox, which instructs Simple Inkscape Scripting to issue only a warning message upon failure to import NumPy and/or Pillow. Operations that require those packages will crash, but all other operations will run as normal.
- The
translatemethod accepts arelocateargument, which can be used to rewrite the object's coordinates rather than apply a transformation matrix.
A few nasty bugs have been squashed as well.
See the Simple Inkscape Scripting commit log for details of all of the above. Also, a PDF version of the complete online documentation is provided as a release asset named sis-docs.pdf.
Simple Inkscape Scripting v5.2.0
This release of Simple Inkscape Scripting introduces a number of (I hope) useful features:
- Page objects, such as those created by
pageor retrieved usingall_pages, expose anall_shapesmethod, which can return either all shapes that intersect the page or all shapes fully contained by the page. - Characteristics of Inkscape's user interface can be queried and modified using the
guiobject. - Rectangular, axonometric, and modular grids can be added to the document. Grids also can be removed and modified.
- The top-level
all_shapesfunction now truly returns all shapes in the document, including those not created by the user's script. - An
all_layersfunction returns a list of all layers in the document.
In addition, get_parent should behave as expected when invoked on an object not created by the user's script.
See the Simple Inkscape Scripting commit log for details of all of the above. Also, a PDF version of the complete online documentation is provided as a release asset named sis-docs.pdf.
Simple Inkscape Scripting v5.1.0
This is a minor release of Simple Inkscape Scripting which provides a number of small improvements relative to the last major release:
reprproduces meaningful output for all Simple Inkscape Scripting objects.- Even images specified by URL can be embedded in a document. Previously, only local files could be embedded.
- A new example,
examples/pixels_to_rectangles.py, shows how to call the Python Imaging Library from within a Simple Inkscape Scripting script. - The extension has been made compatible with Inkscape versions up to 1.5.
- Support is provided for using Simple Inkscape Scripting functions and classes in other extensions. See the new Derived Extensions wiki page.
There is also one very small breaking change:
- The second argument to shape-transformation methods
rotate,scale, andskewis now calledanchorinstead ofaround.
Because the documentation has always referred to this argument as anchor, I'm considering the correction to the code a minor change rather than a major change.
See the Simple Inkscape Scripting commit log for details of all of the above.
Simple Inkscape Scripting v5.0.0
This is a major new release of Simple Inkscape Scripting. It includes only one—very small—breaking change plus a lot of new features and other improvements.
Breaking change: ungroup applies the group's transform to each ungrouped object.
Reason: Retaining an object's appearance when it is ungrouped matches Inkscape's behavior and should be more intuitive.
Replacement: Pass preserve_transform=False as the final argument to ungroup to recover the pre-v5.0.0 behavior.
In addition to the above and the usual sorts of bug fixes, Simple Inkscape Scripting v5.0.0 provides a long list of new features:
- Foreign XML can be included in an SVG file with the
foreignfunction. This enables, for instance, the embedding of arbitrary HTML within an SVG document. - Document metadata (title, author, copyright, description, etc.) can be both read and written via the
metadatavariable. - A script can query its own filename with the
script_filenamevariable. - Guides can be assigned labels. Labels of existing guides can be read and modified.
- Inkscape actions can be invoked from a script using the
apply_actionfunction. Most operations the Inkscape GUI can perform are backed by an action, makingapply_actiona very powerful addition to Simple Inkscape Scripting. Runinkscape --action-listfor a list of available actions. - A specialization of
apply_actioncalledapply_path_operationsimplifies the invocation of path operations such as path union, path intersection, and path difference. - As a convenience,
+,-,*,^,/, and//can be applied to path objects to perform respectively path union, path difference, path intersection, path exclusion, path division, and path cut. - Simple Inkscape Scripting has been updated to work with Inkscape 1.3.
- When saving an SVG document to a Simple Inkscape Scripting script, paths are written in terms of
inkex PathCommands instead of strings. That is, instead of
path(['M', 8.7, 4.0, 'L', -2.2, 0.02, 'L', 8.7, -4.0, 'C', 7.0, -1.6, 7.0, 1.6, 8.7, 4.0, 'z'])the generated script will contain
path([Move(8.7, 4.0), Line(-2.2, 0.02), Line(8.7, -4.0), Curve(7.0, -1.6, 7.0, 1.6, 8.7, 4.0), zoneClose()])- Transformation methods (
translate,rotate,scale, andskew) can be chained. Thus,
my_shape.scale(1.5, 'ul')
my_shape.rotate(14, 'c')can be written more tersely as
my_shape.scale(1.5, 'ul').rotate(14, 'c')- Transformation methods accept
nw,ne,se, andswas synonyms for the anchor pointsul,ur,lr, andll, respectively. Additional anchor pointsn,e,s, andware supported. - The
to_pathmethod now works on text objects. - A new
z_sortfunction sorts a list of Simple Inkscape Scripting objects by increasing Z-order. - A shape's parent object (group or layer) can be retrieved with the
get_parentmethod.
See the Simple Inkscape Scripting commit log for details of all of the above.
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
imagefunction can embed SVG files, not just PNG and JPEG files, as images. - An
objects_from_svg_filefunction merges SVG objects from another document into the current document. - The
ungroupmethod returns a list of objects that were released from the group. - The
clip_pathandmaskfunctions accept a list of objects in addition to a single object. - Scripts can accept command-line arguments, provided via the
user_argsvariable. - The Simple Inkscape Scripting extension itself (an
inkex.extensions.EffectExtensionobject) is accessible asextension. - Path objects support
translate_path,rotate_path,scale_path, andskew_pathmethods, which modify the path's control points themselves. - An
unremovemethod re-adds to the document an object that was removed withremove. - The
save_filefunction saves the current document to an SVG file. - Two Simple Inkscape Scripting objects are considered equal if they share an underlying
inkexobject. - 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_familystyle 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
canvasobject 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
pagecommand. - The
all_pagesfunction returns a list of all pages in the document. - An
inkex.colors.Colorcan be used directly in a style attribute (typicallyfillandstroke). - The
randcolorfunction 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.
Simple Inkscape Scripting v3.2.0
Here's what's noteworthy in this release of Simple Inkscape Scripting:
- accurate bounding-box calculations for text and images,
- support by all shape constructors for applying a transparency mask,
- the ability to remove and group SVG objects converted to Simple Inkscape Scripting objects with
all_shapes,selected_shapes, orinkex_object, - an
auto_regionparameter tofilter_effectthat selects between automatic and manually specified filter regions, - code restructuring to support Visual Studio Code integration (see #55),
- improved compatibility across past, current, and forthcoming versions of Inkscape, and
- multiple code improvements and bug fixes.
See the Simple Inkscape Scripting commit log for details of all of the above.
Simple Inkscape Scripting v3.1.0
The main feature introduced in this minor release is support for creating and modifying Inkscape guides. In addition, scripts can now safely invoke sys.exit if they want to terminate prematurely.
Simple Inkscape Scripting v3.0.0
This is a long overdue, major release of Simple Inkscape Scripting. It includes a large number of changes, a few of which are breaking changes and may require modifications to existing scripts.
-
The extension is now compatible with Inkscape 1.2-dev.
-
The
text_path.pyexample no longer includes UTF-8-encoded characters because these confuse Windows, which expects Windows-1252 or some other non-standard encoding. -
Objects can be removed by invoking their
removemethod (analogous to Inkscape's Edit → Delete). -
Objects can be ungrouped by invoking
ungroupon their containing group (analogous to Inkscape's Object → Ungroup). -
Shape objects provide a
to_pathmethod that converts them to a path (analogous to Inkscape's Path → Object to Path). -
Simple Inkscape Scripting objects provide a
get_inkex_objectmethod that returns the underlyinginkexobject, which can be used for low-level SVG manipulation. -
A
duplicatemethod creates an independent copy of an object (analogous to Inkscape's Edit → Duplicate). -
push_defaultsandpop_defaultsmethods save and restore the current default transform and style. -
A shape's style can be read and modified via the
stylemethod. -
Inkscape live path effects (LPEs) can be instantiated using the
path_effectfunction and applied to a path using theapply_path_effectmethod. -
Objects created by Simple Inkscape Scripting no longer are grouped automatically but rather are applied individually to the canvas as one would expect.
-
Existing objects can more easily be modified using
transform,rotate,scale, andskewmethods. -
For debugging, an
svgmethod returns an object's underlying SVG code as a string. -
Filters (analogous to Inkscape's Filters) can be created using the
filter_effectfunction and applied to an object using itsfilterattribute. -
Paths can be reversed using the
reversemethod (analogous to Inkscape's Path → Reverse). -
Paths can be appended using the
appendmethod, which can be used for cutting holes in closed paths. -
Objects can be reordered within their group or layer by invoking their
z_ordermethod (analogous to Inkscape's Object → Raise to Top, Raise, Lower, and Lower to Bottom). -
An object's underlying SVG element's tag (e.g.,
circleorgorimage) can be retrieved using thetagmethod. -
Attributes of an underlying SVG object can be read with the
svg_getand written with thesvg_setmethod. -
Existing shapes on a canvas can be retrieved using the
all_shapesandselected_shapesfunctions. -
A number of unit tests are defined and scheduled to run automatically via GitHub Actions on each push to the repository.
-
The
more_textfunction has been replaced by anadd_textmethod on text objects.
Simple Inkscape Scripting v2.1.0
Simple Inkscape Scripting has added a lot of nice, new features since the previous release. Here's what you can look forward to if you upgrade:
-
Clipping paths can be applied to objects.
-
Transformations can be applied/modified after object creation.
-
Objects can be animated. (Inkscape doesn't display SVG animations, but most Web browsers do.)
-
Objects can be converted to definitions. This is useful for creating template objects then instantiating (cloning) them with different transformations applied.
-
Markers (e.g., arrowheads) can be created and applied to paths.
-
Objects can be made into hyperlinks that can be followed when the SVG image is viewed in a Web browser.
-
Pre-defined conversion constants
px,mm,cm,pt, andinchare provided to facilitate the use of absolute sizes and distances.
Simple Inkscape Scripting v2.0.0
This is a major new release of Simple Inkscape Scripting. You'll definitely want to upgrade to pick up all the exciting new features!
Breaking API changes
The API has been made more consistent in terms of scalar versus tuple/list arguments. Items serving the same purpose are now consistently 2-tuples (for two of the same item) or lists (for varying numbers of items). For example, x and y radii are now specified as a single tuple, and lists of coordinates are now specified as a list rather than as an arbitrary number of individual arguments. These changes affect, in particular, ellipse, polyline, polygon, arc, and path. Please update your existing Simple Inkscape Scripting scripts accordingly.
For convenience, arc accepts a scalar radius as a shorthand for a tuple containing two of the same radii; and path can accept a single string in addition to a list of terms, as the former may be helpful when copying and pasting from an existing SVG path string.
Other improvements
There are a lot these. Look at all the good things you get when you upgrade to Simple Inkscape Scripting v2.0.0:
-
The distribution includes an output extension that lets you save an SVG image as a Simple Inkscape Scripting script. Go to File → Save a Copy… and select
Simple Inkscape Scripting script (*.py)from the pull-down menu. -
SVG filter effects can be defined using the new
filterfunction. -
All Simple Inkscape Scripting shape objects provide a new
bounding_boxmethod. -
rectcan additionally draw rounded rectangles. -
Simple Inkscape Scripting objects define a Python
__str__method that converts them to a string of the formurl(#object-id). This enables them to be used as style values (which are automatically converted to strings). For example, text can be flowed into a frame withshape_inside=frame object. -
textaccepts an optionalpathargument that typesets the text along a path. -
New
linear_gradientandradial_gradientfunctions (and the correspondingadd_stopmethod) support the creation of gradient patterns, which can be used as arguments tofillandstroke. -
Scripts no longer need to declare their own functions as
globalin order to invoke them. -
Simple Inkscape Scripting's
printstatement has been redefined to accept multiple arguments, just like Python's built-inprintstatement. -
For advanced users, the root of the SVG XML tree is made available via an
svg_rootvariable. -
Layers can be created with the new
layerfunction. -
The
addmethod ongroup- andlayer-produced objects accepts a list of objects in addition to a single object. -
All of
inkex.pathsis imported into the script's namespace. This provides convenient access to path-element constructors such asMove,Line, andCurve. -
Transformfrominkex.transformsis imported into the script's namespace. This provides a rich mechanism for manipulating object transformations.Transformobjects can be used as a shape-creation function'stransformparameter.
Whew! More examples are included in the examples/ directory to demonstrate usage of these new features. There are also myriad improvements to the Simple Inkscape Scripting code itself, making it cleaner and more robust, but that are not visible to users.