#/bin/bash # Copyright (C) 2010 LAFKON/Christoph Haag. # ---------------------------------------------------------------------- # # This is free software, and you may redistribute it under the GPL. # This Software comes with absolutely no warranty. # For details see the license: http://www.forkable.eu/utils/licenses/gpl # ---------------------------------------------------------------------- # # http://www.forkable.eu/generators/i-bd/i/TRUNK/separateLayers--1-00.sh # ______________________________________________________________________ # # # Extract layers from an inkscape SVG files and write them to .tmp files. # This require an supplemental tag 'layerid'. # ______________________________________________________________________ # TMPDIR=tmp; rm $TMPDIR/*.layer INCLUDE="\-\-5\-" EXCLUDE="BASH|offset" GRPOPEN=\ HEADEND=\ DATE=`date +%y%m%d`; TIME=`date +%H%M%S` #----------------------------------------------------------------------- # # FOR EVERY SVG: WRITE LAYERS TO TMP FILES (ONE LAYER -> ONE TMP FILE # #----------------------------------------------------------------------- # for SVG in `ls . | egrep "$INCLUDE" | egrep -v "$EXCLUDE" | grep svg` do TOTAL=`wc -l $SVG | cut -d ' ' -f 1`; COUNT=1 # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # for GRPSTART in `grep -n $GRPOPEN $SVG | cut -d ':' -f 1` do GRPEND=`cat -n $SVG | \ sed -n "${GRPSTART},${TOTAL}p" | \ grep $GRPSHUT | \ cut -f 1 | \ head -1` ISALAYER=`sed -n "${GRPSTART},${GRPEND}p" $SVG | \ grep inkscape:groupmode=\"layer\" | \ wc -l` if [ $ISALAYER -eq 1 ]; then COUNTGRPOPEN=`sed -n "${GRPSTART},${GRPEND}p" $SVG | \ grep $GRPOPEN | wc -l` GRPEND=`cat -n $SVG | \ sed -n "${GRPSTART},${TOTAL}p" | \ grep $GRPSHUT | \ cut -f 1 | \ head -$COUNTGRPOPEN | tail -1` NAME=`echo $SVG | cut -d "." -f 1`; UNINAME=`echo 0000${COUNT} | rev | cut -c 1-4 | rev` UNINAME=${NAME}_${UNINAME} echo $UNINAME; COUNT=`expr $COUNT + 1` sed -n "${GRPSTART},${GRPEND}p" $SVG > $TMPDIR/$UNINAME.layer fi done # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # done # ---------------------------------------------------------------------- # # ADD MISSING CLOSING TAGS (=BUG) # for LAYERFILE in `ls $TMPDIR/*.layer` do COUNTGRPOPEN=`grep $GRPOPEN $LAYERFILE | wc -l` COUNTGRPSHUT=`grep $GRPSHUT $LAYERFILE | wc -l` TEST=`expr $COUNTGRPOPEN - $COUNTGRPSHUT` while [ $TEST -gt 0 ] do echo $GRPSHUT >> $LAYERFILE TEST=`expr $TEST - 1` done done # --------------------------------------------------------------------- # exit 0;