Guest
2011-03-02, 01:54 AM
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..