The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniGraffle > OmniGraffle General
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
Script: Select Peers Thread Tools Search this Thread Display Modes
OmniGraffle Edit > Select offers ancestors and descendants but not siblings and cousins.

Here is a rough draft of a script which selects all shapes or lines at the same level of nesting (same rank/row) as the selected shape(s) and or line(s). (A whole generation of links and/or shapes within the tree).



Code:
property pTitle : "Select Peers"
property pVer : "0.5"

-- Ver 0.2 slightly more efficient
-- Ver 0.3 slightly simpler
-- Ver 0.4 exits with message if the graph is a loop
-- Ver 0.5 intended to work with Lion FullScreen mode

on run
	tell application id "OGfl"
		activate
		if my isFullScreen("OGfl") then
			set oWin to window 2
		else
			set oWin to window 1
		end if
		
		tell oWin
			-- QUIT IMMEDIATELY IF NOTHING IS SELECTED
			try
				set lstSeln to selection
			on error
				return
			end try
			
			-- GET THE DEPTHS (AND TREE ROOTS) OF ANY SELECTED SHAPES OR LINES
			set lstLevels to {}
			
			repeat with oSeln in lstSeln
				set lstAncestors to {}
				set oLevel to my GetLevel(oSeln, 1, lstAncestors)
				if first item of oLevel is missing value then
					display dialog "Not a tree - loop detected" buttons {"OK"} default button "OK" with title pTitle & "  ver. " & pVer
					return
				end if
				set end of lstLevels to oLevel
			end repeat
			
			
			-- LIST OTHER SHAPES OR LINES AT THE SAME LEVEL BENEATH THE SAME ROOT
			set lstSeln to {}
			repeat with oLevel in lstLevels
				set {cClass, oRoot, lngLevel} to oLevel
				set lstSeln to lstSeln & my LevelGraphics(oRoot, cClass, lngLevel)
			end repeat
			
			-- SELECT THE PEER SHAPES OR LINES
			set selection to lstSeln
		end tell
	end tell
end run

-- GET THE DEPTH OF A GRAPHIC UNDER THE ROOT OF ITS TREE
-- (CALL AT TOP LEVEL WITH 1 AS A lngBaseLevel ARGUMENT
on GetLevel(oGraphic, lngBaseLevel, lstAncestors)
	tell application id "OGfl"
		tell oGraphic
			set lngID to id
			if lngID is in lstAncestors then
				return {missing value, missing value, missing value}
			end if
			set cClass to class
			if cClass is shape then
				if incoming lines ≠ {} then
					return my GetLevel(source of first incoming line, lngBaseLevel + 1, lstAncestors & lngID)
				else
					return {cClass, oGraphic, lngBaseLevel}
				end if
			else if cClass is line then
				set {_, oGraphic, lngBaseLevel} to my GetLevel(source, lngBaseLevel + 1, lstAncestors & lngID)
				return {cClass, oGraphic, lngBaseLevel}
			else
				return {missing value, missing value, 0}
			end if
		end tell
	end tell
end GetLevel


-- RETURN THE SHAPES AT A CERTAIN DEPTH BELOW THE SPECIFIED ROOT
on LevelGraphics(oRoot, cClass, lngLevel)
	tell application id "OGfl"
		if lngLevel = 1 then
			if cClass ≠ shape then
				return (incoming lines of oRoot) as list
			else
				return {oRoot}
			end if
		else
			set lstLevel to {}
			repeat with oChild in (destination of outgoing lines of oRoot) as list
				set lstLevel to lstLevel & my LevelGraphics(oChild, cClass, lngLevel - 1)
			end repeat
			return lstLevel
		end if
	end tell
end LevelGraphics

on isFullScreen(strAppID)
	tell application "Finder" to set blnPreLion to (version < "10.7")
	if blnPreLion then
		return false
	else
		tell application id "sevs"
			set lstApps to application processes where creator type = strAppID
			if length of lstApps < 1 then return false
			set lstWins to windows of first item of lstApps
			if length of lstWins < 1 then return false
			return value of attribute "AXFullScreen" of item 1 of lstWins
		end tell
	end if
end isFullScreen
Attached Thumbnails
Click image for larger version

Name:	Screen shot 2012-01-01 at 17.17.38.png
Views:	721
Size:	21.2 KB
ID:	2174  

Last edited by RobTrew; 2012-01-07 at 11:40 AM.. Reason: Ver 0.5 should now work with Lion FullScreen window
 
Selecting all shapes or links at particular levels may, of course, be particularly hard to to do by eye and mouse when layouts are radial.

A bit easier by script.

(Ver 0.4 above should now exit gracefully with a warning if the diagram turns out to be a cyclic graph rather than a hierarchy)

--
Attached Thumbnails
Click image for larger version

Name:	Screen shot 2012-01-03 at 14.46.40.png
Views:	402
Size:	29.6 KB
ID:	2182  

Last edited by RobTrew; 2012-01-03 at 07:20 AM..
 
Ver 0.5 above should, in principle, now work in a Lion FullScreen window as well as in an ordinary front window.
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
setting project + context via script (modifying a DEVONthink script) bernd OmniFocus Extras 2 2012-09-08 12:10 PM
Select behind artdog OmniGraffle General 3 2010-09-09 02:50 AM
select all in sidebar etc. Craig OmniFocus Extras 6 2009-09-22 12:06 PM
How to select? davidamis OmniFocus Extras 2 2009-04-08 09:09 AM
non-linear select bjordan OmniOutliner 3 for Mac 1 2007-08-09 11:23 AM


All times are GMT -8. The time now is 03:23 PM.


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