Inkscape.org
Creating New Extensions Use inkex from command line
  1. #1
    Phos Phos @Phos

    Is inkex supposed to be run from inkscape only or can it be run from command line as well. I have an extension that currently runs on objects selected in inkscape using`self.svg.selection.rendering_order()`. However when I run it from command line, I want it to process all elements in the svg or perhaps have user pass elements id as arguments so that only they can be process.

    Is it possible?

  2. #2
    inklinea inklinea @inklinea⛰️

    Assuming you just want to use inkex via python on the Windows command line.

    These steps do not require Inkscape to be installed

    However, in my case I do not have python installed seperately so the python installed with Inkscape is being used.

    Something like this:

    py -m venv inkvenv

    (where inkvenv is just a name I chose for a new venv)
    You may have to wait a couple of minutes for it to install

    Then

    cd inkvenv\Scripts

    activate.bat

    You should then be inside you own custom venv.

    pip install inkex

    (this will pull inkex from pypi)

    then to test it:

    py

    At the prompt type

    import inkex

    then exit()

    To test inkex is working from the command line:

    make a small .py file

    import inkex

    inkex.errormsg('testing inkex')

    save it as debug.py

    then from the command line

    py debug.py

    -------------------------------------------
    As mentioned this is completely separate from Inkscape itself, just using inkex as a python module.

    Using the Inkscape command line (ie the Inkscape executable with options / actions) is a different topic.

    If you invoke and extension from the Inkscape command line, it's not currently possible to pass parameters to that extension (Inkscape 1.4)