Thread: Calculate area View Single Post
 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