Skip to content

Instantly share code, notes, and snippets.

@joatmon08
Created October 13, 2021 13:27
Show Gist options
  • Save joatmon08/5236c4fce83138ca3d7382a205b3597b to your computer and use it in GitHub Desktop.
Save joatmon08/5236c4fce83138ca3d7382a205b3597b to your computer and use it in GitHub Desktop.
Draw.io Export Script

Draw.io Export Script

For diagrams in books and other content.

Prerequisites

  • Mac OS X (run on Intel)
  • Draw.io v15.4.0+

Run

You can run this script in your directory of graphics. The directory should look as follows:

$ tree -L 1
.
├── CH\ 01
├── CH\ 02
├── CH\ 03
└── export.sh

You need to download the ${CHAPTER_NO_SPACES}.drawio file into the corresponding chapter directory.

Then, check the number of figures in the diagram set. (Unfortunately, there's no way to export all.)

Run the following in your shell. The arguments include the directory, the prefix for the chapter, the number of figures, and the suffix you want to append.

$ bash export.sh "CH 02" CH02 8 Wang

After you run it, you get the diagrams in *.png and *.svg form.

#!/bin/bash
FILE_PATH=$1
CHAPTER=$2
PAGES=$3
SUFFIX=$4
PAGES=$((PAGES-1))
cd "$FILE_PATH"
mkdir -p png
mkdir -p svg
for i in $(seq 0 $PAGES)
do
printf -v FIGURE "F%02d" $((i+1))
/Applications/draw.io.app/Contents/MacOS/draw.io -x -f png -s 1 -o "png/${CHAPTER}_${FIGURE}_${SUFFIX}.png" -p $i "$CHAPTER.drawio"
/Applications/draw.io.app/Contents/MacOS/draw.io -x -f svg -s 1 -o "svg/${CHAPTER}_${FIGURE}_${SUFFIX}.svg" -p $i "$CHAPTER.drawio"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment