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 Extras
FAQ Members List Calendar Today's Posts

 
Select Descendants - using Applescript Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Edit > Select > Descendants is one of the things I reach for most in the OmniGraffle menu.

(For example en route to reformatting a sub-tree with a color-toggling script)

Here is a way of doing it in Applescript, perhaps as a preamble to some formatting code.

Code:
-- EXTEND SELECTION TO ALL DESCENDANTS OF CURRENT SELECTION(s)

on run
	tell application id "com.omnigroup.OmniGrafflePro"
		try
			tell front window
				set lstSeln to its selection
				set oCanvas to its canvas
			end tell
		on error
			return
		end try
		set lngSelns to count of lstSeln
		if lngSelns < 1 then return
		
		-- GET THE WHOLE SET OF SUB-TREES (EACH SELECTION AND ALL THEIR DESCENDENTS)
		set lstChiln to {}
		set lstAncestors to {}
		repeat with i from 1 to lngSelns
			set oSeln to item i of lstSeln
			if (class of oSeln = shape) then
				set refLines to (a reference to outgoing lines of oSeln)
				set lngLines to count of refLines
				set end of lstAncestors to id of oSeln
				if lngLines > 0 then set lstChiln to lstChiln & my GetDescendants(oCanvas, refLines, lngLines, lstAncestors)
			end if
		end repeat
		
		-- AND EXTEND THE SELECTION TO ALL SHAPES IN THE SUBTREE.
		set selection of front window to lstSeln & lstChiln
	end tell
end run

-- GET THE SHAPES (AND THE DESCENDANTS OF THE SHAPES) AT THE END OF THESE LINES
on GetDescendants(oCanvas, refLines, lngLines, lstAncestors)
	set lstChiln to {}
	tell application id "com.omnigroup.OmniGrafflePro"
		repeat with i from 1 to lngLines
			set lstShapes to (shapes of oCanvas where incoming lines contains (item i of refLines))
			set lngShapes to count of lstShapes
			if lngShapes > 0 then
				repeat with j from 1 to lngShapes
					set oChild to item j of lstShapes
					set strID to id of oChild
					if lstAncestors does not contain strID then
						set end of lstChiln to oChild
						set lstChildLines to (outgoing lines of oChild)
						set lngChildLines to count of lstChildLines
						if lngChildLines > 0 then set lstChiln to lstChiln & my GetDescendants(oCanvas, lstChildLines, lngChildLines, lstAncestors & strID)
					end if
				end repeat
			end if
		end repeat
	end tell
	return lstChiln
end GetDescendants

Last edited by RobTrew; 2011-03-02 at 08:24 AM..
 
 




Similar Threads
Thread Thread Starter Forum Replies Last Post
Select behind artdog OmniGraffle General 3 2010-09-09 02:50 AM
How to select? davidamis OmniFocus Extras 2 2009-04-08 09:09 AM
Select from one item to another? Roger Barre OmniOutliner 3 for Mac 0 2008-09-07 09:38 AM
How to select all level n vanity OmniOutliner 3 for Mac 6 2008-01-25 12:31 PM
non-linear select bjordan OmniOutliner 3 for Mac 1 2007-08-09 11:23 AM


All times are GMT -8. The time now is 04:54 PM.


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