Inkscape.org
Beyond the Basics Using the CLI to flip existing text in an svg
  1. #1
    MarcusBrinsden MarcusBrinsden @MarcusBrinsden

    Hi there can someone help me?

    I'm trying to use the CLI to flip text individually in an svg.

    inkscape --actions="select-by-element:text;transform-scale:-100;FileSave;FileClose" --batch-process C:\Temp\FlynnHouseinkscape.svg

    but this just shrinks and doesn't flip.

     

    Basically the CLI needs to reproduce the behaviour shown here...

    Horizontal flip a group without affecting text objects - Beginners' Questions - Inkscape Forum

     

  2. #2
    Polygon Polygon @Polygon🌶

    Forward from Chat:

    this is in one of the examples so they probably can: ObjectFlipVertically 
    just saw this so yes they can: ObjectFlipHorizontally

    https://wiki.inkscape.org/wiki/index.php?title=Using_the_Command_Line#Modify_files

    Just collecting info. Never used CLI.

  3. #3
    MarcusBrinsden MarcusBrinsden @MarcusBrinsden

    Thanks I've been all over that site but no real info about whether i can do it.   Maybe I can pass this to a developer?

  4. #4
    Polygon Polygon @Polygon🌶

    Do you mind to chime in here? https://chat.inkscape.org/channel/inkscape_user

    It´s about your question right now.

  5. #5
    inklinea inklinea @inklinea⛰️

    For simple conversion ( original files will be overwritten - so ***please*** use copies ) 

    inkscape --batch-process --actions="select-by-element:text;ObjectFlipHorizontally;FileSave;" *.svg

    will convert and resave every svg file in the folder


    For better (safer) batch conversion ( use with script ) below can be used.

    export-filename: would usually use a filename generated by bash in linux or powershell in windows 10

    inkscape --batch-process --actions="select-by-element:text;ObjectFlipHorizontally;export-filename:flipped.svg;export-do;" drawing.svg


    Please note: 

    It's possible but not that likely you might come across a nested <text></text> in which case results my not be predictale. <tspan></tspan> children should be okay.

    Any command line what use Inkscape menu verbs - the gui is essential. ( That's what --batch-process does - closes the gui at the end of each command. It wouldn't work in Inkscape --shell mode etc.

  6. #6
    inklinea inklinea @inklinea⛰️
    *

    I had another look at the files you want to flip. 

    The files have some text labels which are made of more than one text element aligned next to each other:

    For example instead of <text>Text Label</text>

    We have <text>Text </text><text>Label</text>

    So looping through and flipping each item does solve the problem.

    I have attached a video.

    Peek 2021 10 08 23 37
  7. #7
    MarcusBrinsden MarcusBrinsden @MarcusBrinsden

    Thanks.  Can you send me the CLI commands that does this?  I'll be able to take it from there.

     

    Thanks again this is great!

  8. #8
    inklinea inklinea @inklinea⛰️

    I've uploaded the extension to:  https://gitlab.com/inklinea/mirror-text

    A few notes:

    Requires Inkscape 1.1+

    Very poor efficiency - using command line calls is not the best way to do this, probably better to apply transformations in python itself using the inkex transform module

    The gui actually becomes visible when using the command line, that would indicate just how inefficient it is.

    The way the measurements exist in your files  - they are constructed from aligned separate text elements, so 4.5m x 2.5m would become 2.5m x 4.5m, which is obviously a problem ( potentially very expensive if this related to the real world )

    Extension verbs memorise the last settings which were used normally in Inkscape, as long as Inkscape exited cleanly.

    inkscape --batch-process --actions="org.inkscape.inklinea.flip_text;export-filename:flipped.svg;export-do;" ./drawing.svg

    Anyway - it's another thing which exists in the world :)

  9. #9
    MarcusBrinsden MarcusBrinsden @MarcusBrinsden

    Thanks I'll have a look.

    Again I appreciate your help, at the very least it will help me on how to tackle this problem.

  10. #10
    MarcusBrinsden MarcusBrinsden @MarcusBrinsden

    So in regards to the separate text elements issue...we are using inkscape cli to process a pdf from our CAD system to create the svg.  I'll investigate to see if there's a way keep text elemants "whole" when processed.

Inkscape Inkscape.org Inkscape Forum Beyond the Basics Using the CLI to flip existing text in an svg