The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniGraffle General (http://forums.omnigroup.com/forumdisplay.php?f=10)
-   -   Highlighting a path in Omnigraffle Pro 5.3.6 (http://forums.omnigroup.com/showthread.php?t=24800)

Mbas 2012-07-03 07:51 AM

Highlighting a path in Omnigraffle Pro 5.3.6
 
Hi. I have a tree of connected objects in my canvas. I want to highlight a path between the leaf and the root every time I click on the leaf object. All my leaves and the root are normal shapes that are connected through lines. One way I have thought about it is writing an applescript that highlights the lines leading to the root. But I am new to writing scripts and need help there. Any help/suggestions is much appreciated

RobTrew 2012-07-04 12:30 AM

The [I]Edit > Select > Ancestors[/I] menu option is a built-in way of doing something like this, but if you need to do it through Applescript for any reason (to select only ancestral links, or only ancestral nodes, rather than both, for example) a simple sketch might look something like this, which extends the selection up through the ancestral path.

Editing the value of the properties [I]pblnNodes[/I] and [I]pblnLinks[/I] at the start of the script (setting each to [I]true[/I] or [I]false[/I]) will enable you to determine whether it is the ancestral nodes which are highlighted, or the ancestral links, or both.

[CODE]-- ver 0.03

property pblnNodes : true
property pblnLinks : false

tell application id "OGfl"
if (count of documents) < 1 then return
tell front window
set lstPaths to {}
repeat with oShape in (selection as list)
if (class of oShape) is shape then
set lstPaths to lstPaths & my GetPath(oShape, pblnNodes, pblnLinks)
end if
end repeat
set selection to lstPaths
end tell
end tell

on GetPath(oShape, blnNodes, blnLinks)
tell application id "OGfl"
set lstIncoming to incoming lines of oShape
if lstIncoming ≠ {} then
set oLink to first item of lstIncoming
set lstPath to my GetPath(source of oLink, blnNodes, blnLinks)
if blnLinks then set lstPath to lstPath & {oLink}
if blnNodes then set lstPath to lstPath & {oShape}
else
if blnNodes then
set lstPath to {oShape}
else
set lstPath to {}
end if
end if
return lstPath
end tell
end GetPath[/CODE]

[COLOR="White"]--[/COLOR]

RobTrew 2012-07-04 01:55 AM

You should be able to get this to work in response to a Browse Tool click if you specify script actions for particular leaf nodes.

Inspectors > Action > Runs a Script

and enter or paste something like the following:

[CODE]set selection of front window to GetPath(self, true, true)

on GetPath(oShape, blnNodes, blnLinks)
tell application id "OGfl"
set lstIncoming to incoming lines of oShape
if lstIncoming ≠ {} then
set oLink to first item of lstIncoming
set lstPath to my GetPath(source of oLink, blnNodes, blnLinks)
if blnLinks then set lstPath to lstPath & {oLink}
if blnNodes then set lstPath to lstPath & {oShape}
else
if blnNodes then
set lstPath to {oShape}
else
set lstPath to {}
end if
end if
return lstPath
end tell
end GetPath[/CODE]

This works in editing view, but I notice that it generates an error in presentation view. A quick note to the Ninjas thru [B]Help > Send Feedback …[/B] may enable you to learn whether there is a syntax which enables script-driven selection in presentation mode.

[COLOR="White"]--[/COLOR]

RobTrew 2012-07-04 02:10 AM

Mmm …

Doesn't look like it. It seems that none of this is possible in Presentation Mode – 'selection' is only defined for edit mode

RobTrew 2012-07-04 02:16 AM

Finally, to attach the script action to all shapes in the canvas which you are editing, so that any one of them will highlight the ancestral path in response to a click from the Browse tool, you could run something like this:

[CODE]property pScript : "
set selection of front window to getpath(self, true, true)
on getpath(oShape, blnNodes, blnLinks)
tell application id \"OGfl\"
set lstIncoming to incoming lines of oShape
if lstIncoming ≠ {} then
set oLink to first item of lstIncoming
set lstPath to my getpath(source of oLink, blnNodes, blnLinks)
if blnLinks then set lstPath to lstPath & {oLink}
if blnNodes then set lstPath to lstPath & {oShape}
else
if blnNodes then
set lstPath to {oShape}
else
set lstPath to {}
end if
end if
return lstPath
end tell
end getpath"

tell application id "OGfl"
repeat with oShape in shapes of canvas of front window
set script of oShape to pScript
end repeat
end tell[/CODE]

RobTrew 2012-07-05 12:52 PM

3 Attachment(s)
Post finally, I hadn't previously noticed that nodes can inherit a script from the template on which a document is based.

For example, any node in a hierarchy based on the attached template will foreground the color of its own ancestral links, in response to a Browse Tool click, and will gray out all other links in the diagram.

[COLOR="White"]--[/COLOR]

RobTrew 2012-07-05 09:40 PM

Correct file now attached above. (I had inadvertently attached a style in lieu of a template).

john.gersh 2012-07-06 07:44 AM

Rob,

It looks like the script doesn't provide a way to get out of path-highlighting mode.

Perhaps you could add a check for the root node (lstPaths = {}) in the main tell block. A browse tool click on the root would set some normal stroke properties for lines (rather than the background ones) and return.

RobTrew 2012-07-06 11:40 AM

1 Attachment(s)
Hi John,

Yes, that does seem a good idea – a direct test for root status would be an empty [I]incoming lines[/I] collection, and the script to install it in the template nodes might look roughly like this:

[CODE]-- GIVES ALL SHAPES AN ACTION SCRIPT WHICH GRAYS ALL LINKS EXCEPT FOR THE ANCESTRAL LINKS
-- OF THE SHAPE CLICKED WITH THE BROWSE TOOL
-- THE ANCESTRAL PATH IS RECOLORED TO RED
-- CLICKING THE ROOT NODE RESETS TO A DEFAULT

-- ver 0.07
set pScript to "
property pblnNodes : false
property pblnLinks : true

property pNormalColor : {0,0,0} -- black
property pBackColor : {32767, 32767, 32767} -- grey
property pForeColor : {65535, 0, 0} -- red

property pNormalWidth : 1
property pBackWidth : 1
property pForeWidth : 3

set oCanvas to canvas of self
set refLines to a reference to lines of oCanvas
if count of (incoming lines of self) < 1 then
tell refLines
set stroke color to pNormalColor
set thickness to pNormalWidth
end tell
else
set lstPaths to my GetPath(self, false,true)

tell refLines
set stroke color to pBackColor
set thickness to pBackWidth
end tell

repeat with oLine in lstPaths
tell oLine
set stroke color to pForeColor
set thickness to pForeWidth
move it to beginning of refLines -- bring to front, in case of orthogonal overlap
end tell
end repeat
end if

on GetPath(oShape, blnNodes, blnLinks)
tell application id \"OGfl\"
set lstIncoming to incoming lines of oShape
if lstIncoming ≠ {} then
set oLink to first item of lstIncoming
set lstPath to my GetPath(source of oLink, blnNodes, blnLinks)
if blnLinks then set lstPath to lstPath & {oLink}
if blnNodes then set lstPath to lstPath & {oShape}
else
if blnNodes then
set lstPath to {oShape}
else
set lstPath to {}
end if
end if
return lstPath
end tell
end GetPath
"

-- ONLY RUN THIS IF YOU WANT TO APPLY THE SCRIPT ABOVE
-- APPLY SCRIPT ACTION TO *EVERY* SHAPE ON THE CANVAS
tell application id "OGfl"
set script of shapes of canvas of front window to pScript
end tell[/CODE]


All times are GMT -8. The time now is 03:56 AM.

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