Empty Value
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 <<empty>>, but how do I reference that in my code? I want something like: [CODE] if (source of vertex is not equal to <<empty>>) then dft(source of vertex) end if [/CODE] 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[/CODE] |
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 [/code] 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. |
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 [B]not[/B] missing value) -- and these in another ... end tell end tell[/CODE] 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 [I]Filter[/I] section under [URL="http://bit.ly/ASWhere"]Reference Forms[/URL] in the online Applescript documentation). [COLOR="White"]--[/COLOR] |
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 [/code] or even [code] set myGroups to (group of myCanvas whose id is (id of group of vertex)) [/code] both fail when the shape isn't part of a group. |
Well-behaved applescript libraries return [I]missing value[/I] in such cases.
There is, however, a fairly major bug in the OmniGraffle library which is worth reporting through OmniGraffle[B] Help > Send Feedback ...[/B], 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 [I]group, jump, notes, rank group, script, shadow color, shadow vector, stroke color, tag, url, user data[/I]) simply fail to return a value at all when they should return [I]missing value[/I]. 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 [I]properties[/I] 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 [/CODE] |
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. |
All times are GMT -8. The time now is 08:51 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.