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 > Developer > AppleScripting Omni Apps
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
Empty Value Thread Tools Search this Thread Display Modes
I am trying to write a traversal algorithm for my OG document, and am having trouble with lines that do not have nodes on both ends (which is allowed in my document).

Script Debugger tells me that eg/ source is <>, but how do I reference that in my code? I want something like:
Code:
if (source of vertex is not equal to <>) then
  dft(source of vertex)
end if
but this doesn't compile, and "missing value" substituted for empty doesn't work either. What do I need to be writing?
 
This seems to work:

Code:
tell application id "OGfl"
	tell front window 
		set lstShapes to selection
		set oShape to first item of lstShapes
		set lstInLines to (incoming lines of oShape where its source is not missing value)
		repeat with oLine in lstInLines
			-- do something to the line
		end repeat
	end tell
end tell

Last edited by RobTrew; 2011-04-05 at 01:30 AM..
 
Thank you!

Edit: This doesn't actually solve my problem.. because I still want strip some info from the meta data of the line. I have:
Code:
set myIncoming to (incoming lines of vertex)
		
set myCount to count of myIncoming
if (myCount is equal to 0) then
	set pathPrefix to stackLib's push({vertex, missing value},pathPrefix)
	copy pathPrefix to beginning of completedPaths
	set pathPrefix to stackLib's pop(pathPrefix)
else
	repeat with currentLink in myIncoming
		set pathPrefix to stackLib's push({vertex, currentLink}, pathPrefix)
		if ((source of currentLink) is not missing value) then
			set src to source of currentLink
			dft(src)
		else
			copy pathPrefix to beginning of completedPaths
			set pathPrefix to stackLib's pop(pathPrefix)
		end if
		set pathPrefix to stackLib's pop(pathPrefix)
	end repeat
end if
When there is no source I just get a message from saying "No result was returned from some part of this expression" when executing the "if source is missing value" part.

Last edited by cyleigh; 2011-04-10 at 09:19 PM..
 
You just need two passes:

Code:
tell application id "OGfl"
	tell front window
		set lstShapes to selection
		set oShape to first item of lstShapes
		
		set lstNoSourceLines to (incoming lines of oShape where its source is missing value)
		-- Process these in one pass,
		
		set lstOtherLines to (incoming lines of oShape where its source is not missing value)
		--	and these in another ...
		
	end tell
end tell
Try, in applescript, to delegate as much of the logic as possible to where/whose clauses. This can drastically reduce the Apple Event count, which tends to be the main bottleneck in the execution speed of a script. It can cut down programmer time as well ...

(See the Filter section under Reference Forms in the online Applescript documentation).

--

Last edited by RobTrew; 2011-04-11 at 02:47 AM..
 
Rob, thank you very much. That should have been obvious!

As a further question, I'm still not sure how to test for the condition in an if statement? I know it isn't a good idea, but I still want to know how to do it. For example, when testing if a shape is part of a group:
Code:
if (group of vertex is not missing value) then
  -- stuff
end
or even
Code:
set myGroups to (group of myCanvas whose id is (id of group of vertex))
both fail when the shape isn't part of a group.
 
Well-behaved applescript libraries return missing value in such cases.

There is, however, a fairly major bug in the OmniGraffle library which is worth reporting through OmniGraffle Help > Send Feedback ..., because it imposes burdens which other applescript libraries do not: a lot of logic has to be 'Rube Goldberged' rather inefficiently and clumsily with verbose error-handling routines, or indirect property access, in lieu of simple control structures and assignments.

A number of properties (e.g. Shape properties like group, jump, notes, rank group, script, shadow color, shadow vector, stroke color, tag, url, user data) simply fail to return a value at all when they should return missing value.

The fact that this is a bug rather than a design decision becomes clear if you access these same properties indirectly through the object's properties collection. Reached circuitously through this interface they behave correctly.

It looks like some basic and architectural misapprehension may have arisen when the OG applescript library was written ...

Sample snippets:

Code:
tell application id "OGfl"
	tell front window
		set lstShapes to selection
		if length of lstShapes < 1 then return
		set oShape to first item of lstShapes
		
		-- Rube Goldberg:  error handling ... should not be necessary
		try
			set oGroup to group of oShape
		on error
			set oGroup to missing value
		end try
		
		-- Indirect access, through properties record.
		-- it works, even when there is no group, but should NOT be necessary
		set recProps to (properties of oShape) as record
		set oGroup to group of recProps
		
		if oGroup is not missing value then
			set strID to id of oGroup
			
			-- Filtering: requires plural "groups"
			set lstGroup to groups of front canvas where its id is strID
		end if
		
	end tell
end tell

Last edited by RobTrew; 2011-04-11 at 09:33 PM..
 
Rob, thank you. Sorry for the delay in replies, but I only work two days a week, and have a two year old the rest of the time who doesn't leave much head space for applescript!

I had, thankfully, worked out the try-catch situation, but thought that there must have been a better way to deal with the situation. I did wonder if it was a bug, because occasionally, the script doesn't crash - the group check does return missing value. I don't have a use case to show this though.

I have reported this.
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Plug-in Preferences is empty Ward OmniWeb Bug Reports 0 2013-05-06 08:16 AM
How to show non-empty contexts orlick OmniFocus 1 for Mac 2 2011-05-23 07:26 AM
iPhone syncing but empty Augustronīc™ OmniFocus Syncing 1 2009-02-28 06:50 AM
5.5b2: unneeded empty tab endorphinity OmniWeb General 7 2006-08-10 08:10 AM
sp 11 : Bookmarks menu empty & other bug myckmack OmniWeb Bug Reports 2 2006-05-18 08:30 AM


All times are GMT -8. The time now is 05:06 AM.


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