The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniGraffle General (http://forums.omnigroup.com/forumdisplay.php?f=10)
-   -   OmniGraffle Word Count (http://forums.omnigroup.com/showthread.php?t=18355)

RobTrew 2010-10-04 04:23 AM

OmniGraffle Word Count
 
I needed a word count this morning, for all the text in the nodes of a diagram.

In case anyone else needs to do this, here is what I used:

[CODE]-- Word Count for OmniGraffle
-- Ver .001

set text item delimiters to space
tell application id "com.omnigroup.OmniGrafflePro"
set oWin to front window
tell canvas of oWin
set lngWords to count of words of ((text of solids) as text)
set {strCanvas, strDoc} to {name, name of oWin}
end tell
display dialog (lngWords as string) & " words in" & return & return & strCanvas ¬
& " of " & return & return & strDoc buttons {"OK"} with title "OmniGraffle Word Count" with icon 1
end tell
[/CODE]

RobTrew 2010-10-04 05:09 AM

Then, of course, I realised that I also needed to be able to count the words in one or more selected shapes (in addition to the count for the whole canvas).

[IMG]http://farm5.static.flickr.com/4105/5051070436_1b6daec000_o.png[/IMG]

so I needed version two, pasted below.

[CODE]property pTitle : "Word Count for OmniGraffle"
property pVersion : ".002"

-- Ver 2 adds a postscript giving a separate total for words in those shapes which are currently selected.

set text item delimiters to space
tell application id "com.omnigroup.OmniGrafflePro"
set oWin to front window
tell canvas of oWin
set lngWords to count of words of ((text of solids) as text)
set {strCanvas, strDoc} to {name, name of oWin}
end tell

set lngSelnWords to 0
set lngSolids to 0
set lstSeln to selection of oWin
if length of lstSeln > 0 then
repeat with oGraphic in lstSeln
try
set lngSelnWords to lngSelnWords + (count of words of text of oGraphic)
set lngSolids to lngSolids + 1
end try
end repeat
end if

set strReport to (lngWords as string) & " words in" & return & return & strCanvas ¬
& " of " & return & return & strDoc
if lngSelnWords > 0 then
set strReport to ((strReport & return & return & "(Including " & lngSelnWords as string) & ¬
" words in " & lngSolids as string) & " selected " & my pl(lngSolids, "shape") & ")."
end if

display dialog strReport buttons {"OK"} with title pTitle & " Ver " & pVersion with icon 1
end tell

on pl(lngNum, strTerm)
lngNum
if absolute(lngNum) is not 1 then
strTerm & "s"
else
strTerm
end if
end pl

on absolute(num)
if num < 0 then
-num
else
num
end if
end absolute
[/CODE]

DerekAsirvadem 2010-10-04 01:48 PM

Thankyou !


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

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