Skip to content

Instantly share code, notes, and snippets.

@ff6347
Forked from versionsix/README.md
Last active December 3, 2023 13:52
Show Gist options
  • Save ff6347/20f13e00d21b8792918b57d6d40025a7 to your computer and use it in GitHub Desktop.
Save ff6347/20f13e00d21b8792918b57d6d40025a7 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, make all layers invisible except the base layer:
repeat with win_layer from 1 to (count win_layers)
set thisLayer to item win_layer of win_layers
set visible of thisLayer to (name of thisLayer = "Base")
end repeat
-- Now, show each layer, export the image, and make the layer invisible again:
repeat with win_layer from 1 to (count win_layers)
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
set visible of thisLayer to false
end repeat
-- Make all layers visible again:
repeat with win_layer from 1 to (count win_layers)
set thisLayer to item win_layer of win_layers
set visible of thisLayer to true
end repeat
end tell
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