Inkscape.org
Beyond the Basics How to change color in object with shell mode
  1. #1
    Kazuyoshi Kazuyoshi @Kazuyoshi

    Hi,

    Now, I am making a script using Inkscape shell mode.  I would like to change the color of an object.  However, I cannot find the action to do it.

    I have found some insufficient methods so far.  For example, the script at the bottom removes blue only with "org.inkscape.color.remove-blue".  Analogously, we can make blank and white images with "org.inkscape.color.black-and-white".

    However, I cannot change an object's color to an arbitrary color (such as
    rgb(255,192,203) pink).  Please tell me the method.  If we can modify SVG files themselves, I know  that we can use "sed" comand such as
    sed s/1f2f3f/3a3b3c/ig
    But I currently would like to use the shell mode of Inkscape.

    Have a nice week end,
    Kazuyoshi MORI

    (Inkscape v1.4)

    Inkscape-e7c3feb-x86_64.AppImage --shell <<'EOF'                                
    file-open:a0.svg                                                                
    select-by-id:C1Inner                                                            
    org.inkscape.color.remove-blue                                                  
    unselect-by-id:C1Inner                                                          
    export-height:900                                                               
    export-width:1600                                                               
    export-type:png                                                                 
    export-png-compression:0                                                        
    export-filename:xx.png                                                          
    export-do                                                                       
    file-close                                                                      
    EOF           

     

     

     

  2. #2
    inklinea inklinea @inklinea⛰️

    inkscape --actions="object-set-property:fill,green"

    if you want to set the inline style property

    inkscape --actions="object-set-attribute:fill,green"

    if you want to set an attribute. 

     

  3. #3
    Kazuyoshi Kazuyoshi @Kazuyoshi

    Thank you very much, Inklinea!!

    Your kind comment solves my problem immediately.

    Here I present, as an example, an Inkscape script that
    modifies the colors and width of a rectangle.
    Given rectangle has 'fill:#009200' and 'stroke:#e00000'
    (you can see directly these information in a0.svg).
    The script change the colors as 'fill:#1122ee' and 'stroke:#00ccdd'
    and the width to 10.

    Thank you very much again.

    Kazuyoshi MORI, JAPAN

    Inkscape-e7c3feb-x86_64.AppImage --shell <<'EOF'                                
    file-open:a0.svg                                                                
    select-by-id:rect1                                                              
    object-set-property:fill,#1122ee                                                
    object-set-property:stroke,#00ccdd                                              
    object-set-property:stroke-width,10                                             
    unselect-by-id:rect1                                                            
    export-height:900                                                               
    export-width:1600                                                               
    export-type:png                                                                 
    export-png-compression:0                                                        
    export-filename:a0.png                                                          
    export-do                                                                       
    file-close                                                                      
    EOF

     

    A0
    A0
Inkscape Inkscape.org Inkscape Forum Beyond the Basics How to change color in object with shell mode