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

 
AppleScript: Unit Scale and Boolean Operations Thread Tools Search this Thread Display Modes
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
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", ...
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:
-- 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

Last edited by RobTrew; 2012-07-23 at 05:19 AM..
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unit Scale and copy and pasting of elements spl72 OmniGraffle General 0 2011-10-24 08:08 PM
Can't do operations on items selected in list view Leon Starr OmniGraffle General 1 2008-06-23 10:04 AM
Boolean operations Pascal Harris OmniGraffle General 4 2008-05-30 09:34 AM
Unit conversions in AppleScript dmw OmniGraffle General 0 2007-03-27 12:16 PM
Feature unrequest - automatic change of scale unit in Gantt chart gillesp OmniPlan General 0 2006-09-27 03:57 PM


All times are GMT -8. The time now is 07:34 AM.


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