enable/disable layers via command line

Discussion about writing code for Inkscape.
nminkscape
Posts: 5
Joined: Mon Jul 06, 2015 11:56 pm

enable/disable layers via command line

Postby nminkscape » Tue Jul 07, 2015 12:05 am

I have a script (below) which exports from an svg file to png files of various sizes. This works, but I need more. I need to be able to enable and disable layers before the export.
So, for example, just after the "#Android" line, I need to
enable layer "android"
disable layer "ios"


How can I do this?

Code: Select all

set -x

# Windows
INKSCAPE="/C/Program Files/Inkscape/inkscape.exe"
OPTS=--export-background-opacity=0

# OSX
# INKSCAPE="/Applications/Inkscape.app/Contents/Resources/bin/inkscape"
# OPTS=--without-gui --export-background-opacity=0

# Note that directories must already exist before exporting to them

SVG=My_Icon.svg
DEST=generated_icons

# Android
"$INKSCAPE" -w36 $OPTS --export-png=$DEST/android/ic_launcher-ldpi.png $SVG
"$INKSCAPE" -w48 $OPTS --export-png=$DEST/android/ic_launcher-mdpi.png $SVG
"$INKSCAPE" -w72 $OPTS --export-png=$DEST/android/ic_launcher-hdpi.png $SVG
"$INKSCAPE" -w96 $OPTS --export-png=$DEST/android/ic_launcher-xhdpi.png $SVG
"$INKSCAPE" -w144 $OPTS --export-png=$DEST/android/ic_launcher-xxhdpi.png $SVG
"$INKSCAPE" -w192 $OPTS --export-png=$DEST/android/ic_launcher-xxxhdpi.png $SVG
"$INKSCAPE" -w512 $OPTS --export-png=$DEST/android/ic_launcher-web.png $SVG

# iOS
"$INKSCAPE" -w57 $OPTS --export-png=$DEST/ios/ios_icon-57.png $SVG
"$INKSCAPE" -w72 $OPTS --export-png=$DEST/ios/ios_icon-72.png $SVG
"$INKSCAPE" -w114 $OPTS --export-png=$DEST/ios/ios_icon-57-2x.png $SVG
"$INKSCAPE" -w144 $OPTS --export-png=$DEST/ios/ios_icon-72-2x.png $SVG

nminkscape
Posts: 5
Joined: Mon Jul 06, 2015 11:56 pm

Re: enable/disable layers via command line

Postby nminkscape » Fri Nov 11, 2016 3:37 am

bump

Moini
Posts: 1933
Joined: Mon Oct 05, 2015 10:44 am

Re: enable/disable layers via command line

Postby Moini » Fri Nov 11, 2016 7:49 am

Look at the man page and the --verbs-list.
There's a command that toggles the current layer (LayerToggleHide). You will, however, need to select an object in that layer (--select), in order to 'enter' that layer, before you can toggle visibility.
LayerNext and LayerPrev may also come in handy.

Man page: man inkscape or https://inkscape.org/en/doc/inkscape-man.html
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 4 guests