Inkscape.org
Beyond the Basics swap groups in .svg files from command line?
  1. #1
    7jfosqo5 7jfosqo5 @7jfosqo5
    *

    Has anyone attempted already swapping/updating groups in all .svg files from command line? The scenario:

    1. you have the same group used in multiple .svg files

    2. you update that group in one .svg file

    3. now you need to update them in all other files

    4. run something like `inkscape --swap-group group-file.svg *.svg`

     

  2. #2
    inklinea inklinea @inklinea⛰️

    No it's not possible to copy and paste between svgs with the command line along.

    You can load inkex which is the inkscape extension system into a python venv, and manipulate that way.

    There's an example of loading .svg files in this thread:

    https://inkscape.org/forums/beyond/trim-whitespace-from-svg-command-line/

  3. #3
    7jfosqo5 7jfosqo5 @7jfosqo5
    *

    thanks @inklinea, I sensed that some scripting will be necessary - exciting opportunity! Do extensions work from command line however, I'd really like to invoke this functionality from CLI, because of the sheer number of .svg files that need to be processed (dozens) on a frequent basis.

  4. #4
    inklinea inklinea @inklinea⛰️

    If you are using inkex as standalone, it's not an extension as such.

    An extension is a .inx / .py pair that is registered with Inkscape when it runs. 

    (You can run extensions from the command line, however with 1.3 it still requires the --batch-process option which makes it slow as it silently launches the gui in the background.)

    You can put a command call to the cli from the .py file in your venv. I preprocess with inkex standalone, then call the main cli.

    If you want to get really quick, you can preprocess lots of files, then generate a large text file, with an action string on each line.

    Then feed that into Inkscape shell mode, which means Inkscape only lauches the cli once - so less overhead.

  5. #5
    7jfosqo5 7jfosqo5 @7jfosqo5
    *

    That sounds cool, but sorry, one more very basic question. Does inkex need to be run from within inkscape or could it be run headlessly from command line as well? Would it be possible to write a python script that invokes inkscape operations on an svg file without loading the full inkscape? I couldn't see any command line option to load or run a script or extension in `inkscape --help`.  I did see the shell mode that you mentioned and I thought that it was really cool, but more for "macro" like operations, while python provides probably much richer programming environment. Apologies for a possibly noob question. Also, it kind of reminds me of bpy python module for blender, but I've never quite understood this one neither.

  6. #6
    inklinea inklinea @inklinea⛰️

    Yes, inkex ( the inkscape extension api ) https://inkscape.gitlab.io/extensions/documentation/source/index.html is 100% python.

    Unless you use it to make a command call elsewhere. 

    To install it it's as simple as making a new python venv

    switch to that venv using the usual source command

    then

    pip install inkex

    I use it to preprocess svg files, and use the command calls in inkex to access functionallity that is not available in inkex, only via calling the main Inkscape executeable.

    There's an example script at the end of this thread, pre process then call Inkscape.

    https://inkscape.org/forums/beyond/trim-whitespace-from-svg-command-line/


     

  7. #7
    7jfosqo5 7jfosqo5 @7jfosqo5
    *

    That is very cool. When you are saying that "use the command calls in inkex to access functionallity that is not available in inkex, only via calling the main Inkscape executable" I'm hoping that inkex loads only the necessary set of libraries instead of spawning an entire new inkscape subprocess just to perform an operation (e.g. swapping groups in my case). I will try it out, hopefully chatgpt will nudge in the right direction in terms of the specifics of the API itself.

  8. #8
    inklinea inklinea @inklinea⛰️
    *

    [ whoops double post ]

Inkscape Inkscape.org Inkscape Forum Beyond the Basics swap groups in .svg files from command line?