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 Search Today's Posts Mark Forums Read

 
Calculate area Thread Tools Search this Thread Display Modes
Is there a way to calculate the area (square feet) of a shape? I see in variables that I can put height and length in the label of a shape, but I would like to have it calculate the area. Thanks.
 
Hey Rod-

Last year I made a series of "Smart Shapes". I mainly did it upon the stunning realization that creating a shape of double the area (triangle, square or circle) is rather hard. Enter a number in a shape and click (or vice versa), et voila, it scales.

You can download the SmartShapes stencils at

http://oram.com/omni/SmartShapes/

I did this back in the early OG4 beta days, so some things may be flaky. I've pasted a more stable version of the AppleScript below.


- The Applescript/OG bugs in the script are (hopefully) commented out.
- Note that it pays no attention to the scale introduced in OG4. (The scale number is completely arbitrary.)
- If you put a negative number it, the shape turns red, otherwise it's blue.
- The text formatting assumes you are dealing with millions of dollars.

The syntax and text manipulation are pretty self-explanatory, feel free to change whatever you want.

Just paste this AppleScript into the Action pref pane of a shape and things should work.




set z to the text of self
try
set area to z as integer
on error
display dialog "Enter a positive number for cash, or a negative number for debt:" default answer "100"
set z to the text returned of the result
set area to z as integer
end try
if area < 0 then
set area to area * -1
end if
if area = 0 then
display dialog "Enter a positive number for cash, or a negative number for debt:" default answer "100"
set z to the text returned of the result
set area to z as integer
end if
if name of self is "Circle" then
set radius to ((area / pi) ^ 0.5)
set diameter to 2 * radius
set |scale| to 10
set diameter to diameter * |scale|
set size of self to {diameter, diameter}
else if name of self is "Rectangle" then
set |width| to (area ^ 0.5)
set |scale| to 10
set |width| to |width| * |scale|
set height to |width|
set size of self to {|width|, height}
else if name of self is "VerticalTriangle" then
set edge to 2 * ((area / (3 ^ 0.5)) ^ 0.5)
set height to ((3 ^ 0.5) / 2) * edge
set |scale| to 10
set height to height * |scale|
set |width| to edge * |scale|
set properties of self to {size:{|width|, height}}
else
display dialog "Sorry, I only know how to scale squares, circles and equilateral triangles."
end if
if z < 0 then
set fill color of self to {1, 0, 0}
set text of self to "$" & area & "m
debt"
-- set color of text of self to {0, 0, 0} -- this kills OG 3 for some reason
else
set fill color of self to {0, 0, 1}
set text of self to "$" & area & "m
cash"
-- set color of text of self to {1, 1, 1} -- this kills OG 3 for some reason

end if
set text placement of self to top
--set alignment of text of self to center -- OG 4 doesn;t like this...
set size of text of self to 9
 
Great info johnny0... Led me to figuring this out:

set h to x of size of self
set w to y of size of self
set text of self to (h / 72) * (w / 72) as text

I don't know the significance of "72" here yet, but this appears to work for squares/rectangles. Of course this won't work for custom shapes. It would be cool to figure out how to subtract the custom shape from the bound rectangle and figure the area of that, but I am just getting started.. I think I will work on circle and triangles next.
 
Ahhh, that's clever, pixels.

The formulas for triangles and circles are in there too - it's a non-denomishapinal script.

OmniGroup people -- are there references to scale in the OG Applescript dictionary?
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculate Dates? rcherny OmniOutliner 3 for Mac 0 2010-04-01 09:05 AM
Way to calculate duration for a given time period? Dorian OmniFocus Syncing 1 2008-08-31 12:42 PM
Way to calculate duration for a given time period? Dorian OmniFocus 1 for Mac 0 2008-08-31 08:44 AM
Calculate the area of a shape? RAmeeti OmniGraffle General 0 2007-11-13 01:59 PM
Any way to calculate other user accounts if you are admin? JKT OmniDiskSweeper 4 2006-06-01 12:05 PM


All times are GMT -8. The time now is 03:12 PM.


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