Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@zerok
Last active November 19, 2021 19:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zerok/fad81fde8b0462e5fc6d89b694b5b3c4 to your computer and use it in GitHub Desktop.
Save zerok/fad81fde8b0462e5fc6d89b694b5b3c4 to your computer and use it in GitHub Desktop.
OmniGraffle: Export layers on top of base-layer as PNG

Layer export for OmniGraffle

If you have a Graffle document (doc.graffle) with a canvas named "mycanvas" holding the following layers ...

  • Extra 3
  • Extra 2
  • Extra 1
  • Base

... then these images will be generated:

  • doc.graffle-mycanvas-1.png (Layers: Base)
  • doc.graffle-mycanvas-2.png (Layers: Base + Extra 1)
  • doc.graffle-mycanvas-3.png (Layers: Base + Extra 1 + Extra 2)
  • doc.graffle-mycanvas-4.png (Layers: Base + Extra 1 + Extra 2 + Extra 4)
tell application "OmniGraffle"
set thisWindow to first window
set thisDocument to front document
set thisCount to 0
set win_layers to (thisWindow's canvas's layers)
set canvasName to (thisWindow's canvas's name)
set area type of current export settings to current canvas
-- First we have to make every layer except for the
-- base layer invisible:
repeat with win_layer from (count win_layers) to 1 by -1
set thisLayer to item win_layer of win_layers
if win_layer = (count win_layers) then
else
set visible of thisLayer to false
end if
end repeat
-- Now, let's switch them on - one after another - and
-- create a PNG out of the result:
repeat with win_layer from (count win_layers) to 1 by -1
set thisLayer to item win_layer of win_layers
set visible of thisLayer to true
set thisCount to thisCount + 1
set targetFile to (thisDocument's path & "-" & canvasName & "-" & thisCount & ".png")
save thisDocument as "PNG" in POSIX file targetFile
end repeat
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment