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 Today's Posts

 
Highlighting a path in Omnigraffle Pro 5.3.6 Thread Tools Search this Thread Display Modes
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
 
The Edit > Select > Ancestors 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 pblnNodes and pblnLinks at the start of the script (setting each to true or false) 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
--

Last edited by RobTrew; 2012-07-04 at 10:20 AM.. Reason: ver 0.02 allows choice of node or link highlighting, or both
 
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
This works in editing view, but I notice that it generates an error in presentation view. A quick note to the Ninjas thru Help > Send Feedback … may enable you to learn whether there is a syntax which enables script-driven selection in presentation mode.

--

Last edited by RobTrew; 2012-07-04 at 02:05 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
 
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

Last edited by RobTrew; 2012-07-04 at 02:27 AM..
 
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.

--
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2012-07-05 at 21.47.15.png
Views:	459
Size:	32.8 KB
ID:	2442   Click image for larger version

Name:	Screen Shot 2012-07-05 at 21.45.41.png
Views:	459
Size:	33.0 KB
ID:	2443  
Attached Files
File Type: zip Lightning.gtemplate.zip (8.5 KB, 399 views)

Last edited by RobTrew; 2012-07-05 at 09:39 PM.. Reason: Had attached wrong file :-) Template now attached instead of style
 
Correct file now attached above. (I had inadvertently attached a style in lieu of a template).
 
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.

Last edited by john.gersh; 2012-07-06 at 07:49 AM..
 
Hi John,

Yes, that does seem a good idea – a direct test for root status would be an empty incoming lines 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
Attached Files
File Type: zip Lightning3.gtemplate.zip (9.0 KB, 392 views)

Last edited by RobTrew; 2012-07-07 at 02:41 PM..
 
 




Similar Threads
Thread Thread Starter Forum Replies Last Post
Critical Path - won't highlight path aboeing OmniPlan General 4 2014-04-09 12:49 PM
Highlighting in color? hotwheels22 Applying OmniFocus 2 2011-03-27 02:37 PM
Search Field Highlighting Toadling OmniFocus 1 for Mac 4 2008-09-03 09:06 PM
Highlighting problem is 10.5 9A527 gohnjanotis OmniFocus 1 for Mac 2 2007-09-12 02:34 PM
Find - better highlighting? user522j OmniWeb Feature Requests 12 2007-07-01 05:53 PM


All times are GMT -8. The time now is 07:49 PM.


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