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!

 FAQ Members List Calendar Search Today's Posts Mark Forums Read

 rod Member 2006-07-19, 06:14 AM 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. Post 1
 johnny0 Member 2006-07-19, 03:11 PM 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 Post 2
 rod Member 2006-07-19, 05:04 PM 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. Post 3
 johnny0 Member 2006-07-19, 09:18 PM 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? Post 4