AppleScript: Unit Scale and Boolean Operations
This request has two parts.
I am trying to write a script which, given a few parameters, will create a series of shapes and perform boolean operations on them (intersect, subtract, etc.) On top of this I'm trying to use the Unit Scale of the document so the end user can provide a value in feet, but I don't see how/if it's exposed via AppleScript. So for now I'm hard-coding it into the script, i.e. [CODE]set unitscale_left to 1 -- the inches set unitscale_right to 12 -- the feet -- i.e. 1" = 12' in this case set scale_dpi to 72 set unit_scale to scale_dpi / unitscale_right * unitscale_left -- i.e. 6 in this case [/CODE] Using this unit_scale conversion factor, I create two shapes. (Let's say a square and a circle.) In my script, I've kept references to the two shapes as they're returned from OmniGraffle Pro. So far, when I've created primitives, I have been able to use "Copy As Applescript" from the Edit menu in order to see how to reproduce them from a scripting standpoint. However, if I intersect the two shapes manually, I get an object with a crazy-long gibberish name: [CODE]make new shape at end of graphics with properties {name: "1F527F65-F94B-4590-BEFC-0C41E495370B-14690-0000C3313DE014D4", ... [/CODE] Is there a way to cleanly use AppleScript to ask OmniGraffle Pro to intersect two items? If not, I'm guessing I would need to 'do it by hand', or: - Tell the app / window / document / canvas (whatever) to set selected of each of those items to true (or whatever; I don't know the exact syntax here) - Do something with... menu item "Intersect Shapes" of menu "Shapes" of menu item "Shapes" of menu "Edit" of menu bar item "Edit" of menu bar 1 of application process "OmniGraffle Professional" of application "System Events"? Thanks! |
Yes, you have to use your own conversion constants. The AS library uses points and doesn't expose the units choice directly, though you could probably fish it out of the plist file through System Events.
The AS library gives no access to the substructure of intersected shapes, just the UUID handle. (If you want to learn more about them you can unzip the underlying XML file inside a .graffle bundle). And as you suggest, automated intersections thus entail using System Events to make menu choices. Good luck ! |
Sample code fragments (not stand-alone, but perhaps indicative)
[CODE]property pblnUnion : true property pblnSubtract : false -- gather a list of shapes in lstShapes -- ... -- THEN tell application id "OGfl" set oWin to front window set selection of oWin to lstShapes activate -- PERFORM ANY SHAPE UNIONS if pblnUnion then tell application id "sevs" to click (my GetMenuItem("OGfl", {"Edit", "Shapes", "Union Shapes"})) -- PERFORM ANY SHAPE SUBTRACTIONS else if pblnSubtract then tell application id "sevs" to click (my GetMenuItem("OGfl", {"Edit", "Shapes", "Subtract Shapes"})) else assemble lstShapes end if end tell[/CODE] [CODE]-- RETURNS A REFERENCE TO A CLICKABLE MENU ITEM -- E.G. set mnuZoomFit to GetMenuItem("OGfl", {"View", "Zoom", "Zoom to Selection"}) on GetMenuItem(strAppCode, lstMenu) set lngChain to length of lstMenu if lngChain < 2 then return missing value tell application id "sevs" set lstApps to every application process where its creator type = strAppCode if length of lstApps < 1 then return missing value tell first item of lstApps -- GET THE TOP LEVEL MENU set strMenu to item 1 of lstMenu set oMenu to menu strMenu of menu bar item strMenu of menu bar 1 -- TRAVEL DOWN THROUGH ANY SUB-MENUS repeat with i from 2 to (lngChain - 1) set strMenu to item i of lstMenu set oMenu to menu strMenu of menu item strMenu of oMenu end repeat -- AND RETURN THE FINAL MENU ITEM return menu item (item -1 of lstMenu) of oMenu end tell end tell end GetMenuItem[/CODE] |
All times are GMT -8. The time now is 09:52 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.