The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniGraffle General (http://forums.omnigroup.com/forumdisplay.php?f=10)
-   -   Showing/Hiding a notes layer across document using Applescript (http://forums.omnigroup.com/showthread.php?t=10230)

Andrew N 2008-10-15 04:27 PM

Showing/Hiding a notes layer across document using Applescript
 
I am trying to globally show/hide a layer called "Notes" which exists in every canvas using an applescript.

What I have so far is:

[CODE]tell application "OmniGraffle Professional 5"
set theDocument to front document
set canvasCount to count of canvases of theDocument

repeat with canvasNumber from 1 to canvasCount

set canvas of front window to canvas canvasNumber of theDocument
set the visible of layer "Notes" to true
end repeat
end tell[/CODE]

[CODE]set the visible of layer "Notes" to true[/CODE] - OG doesn't like this. In fact I can't work out how to do anything with the layers within a canvas - I can't get Applescript to return how many there are, their names etc.

Any suggestions from a Graffle guru out there?

Thank you!

whpalmer4 2008-10-15 05:42 PM

[QUOTE=Andrew N;48909]
[CODE]set the visbile of layer "Notes" to true[/CODE] - OG doesn't like this. [/QUOTE]

Are you using the same misspelling ("visbile" instead of "visible") in the actual script?

Andrew N 2008-10-16 06:51 AM

[QUOTE=whpalmer4;48910]Are you using the same misspelling ("visbile" instead of "visible") in the actual script?[/QUOTE]

Sorry typo. Visible is the correct spelling!

But, no this isn't the issue. The error I get is "Can't set layer "Notes" to true.

Andrew N 2008-10-16 02:17 PM

OK I have an answer. OG great support provided this script:

[code]tell application "OmniGraffle Professional 5"
set theDocument to front document
set allCanvases to canvases of theDocument
repeat with canvasCount from 1 to (length of allCanvases)
set nextCanvas to item canvasCount of allCanvases
set nextCanvasLayers to layers of nextCanvas
repeat with layercount from 1 to (length of nextCanvasLayers)
set nextLayer to item layercount of nextCanvasLayers
if (name of nextLayer is "Notes") then
set currentVisibility to visible of nextLayer
set visible of nextLayer to not currentVisibility
end if
end repeat
end repeat
end tell[/code]

Seems to work a treat. More complex than I thought...

RobTrew 2008-10-21 11:22 AM

This, which also works, is a simple edit of your code.

[CODE]tell application "OmniGraffle Professional 5"
set theDocument to front document
set canvasCount to count of canvases of theDocument

repeat with canvasNumber from 1 to canvasCount

set oCanvas to canvas canvasNumber of theDocument
set lyrNotes to layer "Notes" of oCanvas
set blnVisible to visible of lyrNotes
set visible of lyrNotes to not blnVisible
end repeat
end tell[/CODE]

Andrew N 2008-10-21 07:55 PM

Thanks Rob - looks like a more efficient piece of code as it doesn't run the embedded repeat function.

jdkunesh 2008-12-08 05:50 PM

Show/Hide notes layer, make printable/non-printable or locked/unlocked
 
Hi guys-

I'm using Omni 5.1. The more verbose script above works, while the more compact one, below it, does not work for me. It compiles but generates an error when I try to use it.

Does every canvas need to have a 'Notes' layer for the second script to work?

Also, I'd like to be able to create print/non-printable and locked/unlocked toggles. Is there somewhere that documents what OMNI exposes to AppleScript like a document object model? I've programmed for 30 years, but never much with applescript before?

Thanks!

RobTrew 2008-12-08 10:25 PM

[QUOTE=jdkunesh;52225]Does every canvas need to have a 'Notes' layer for the second script to work?[/QUOTE]

Yes, but the following redraft should suspend that requirement:

[CODE]tell application "OmniGraffle Professional 5"
set theDocument to front document
set canvasCount to count of canvases of theDocument

repeat with canvasNumber from 1 to canvasCount

set oCanvas to canvas canvasNumber of theDocument
try
set lyrNotes to layer "Notes" of oCanvas
set blnVisible to visible of lyrNotes
set visible of lyrNotes to not blnVisible
end try
end repeat
end tell[/CODE]


Script editing software for Applescript will generally have an "Open Dictionary" command in the menu system (probably under the File menu), which will enable you to look at documentation of an application's object model.

jdkunesh 2008-12-09 12:31 PM

thanks for the help!
 
Thanks Rob!!


All times are GMT -8. The time now is 01:36 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.