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

 
Script for formatting size based on incoming lines Thread Tools Search this Thread Display Modes
This is basically what I want to achieve:

In a diagram, the size of a shape should be decided by the number of incoming lines: If a shape has many incoming lines it should be big, few incoming lines should make a shape small.

I figure an AppleScript is the only way to do this. Unfortunately the world of AppleScript is unknown territory for me.

Any ideas, anyone?

Regards,
Johannes
 
I don't know how to ask this without making your request sound silly, so please forgive me, that is not my intent.

How exactly is the AppleScript module (or whatever code segment is intended to create your shape) supposed to kow how many lines are coming into the shape, or intended to come into the shape ?

Do you want to create a shape (say a simple rectangle), then attach lines to it, then run the script, which re-sizes the shape ... or do you want to tell the script "look, I will have x lines coming in, so create the shape to suit" ?

What about where the lines come in ? Do you only use one side for connection, or can the lines connect to any of the four (or more) sides) ?

Are you wanting this feature for a single shape or to be able to apply it (via exec script) to any shape ?

Are your shapes regular (aligned to grid; size is an integral multiple of Grid/Minor) ... or are they irregular ?

-----

Are you ok with using the Height and Width boxes in the Inspector/Geometry ?

Cheers

Last edited by DerekAsirvadem; 2010-10-11 at 11:18 PM..
 
Thanks for giving me a chance to clarify myself! This is my situation:

I have a very complex diagram with lots of shapes and lines that connect them in various ways. Some of the shapes are more "important" than others in the sense that they have more incoming lines than others. I would like these shapes to be bigger than the not-so-important shapes, and I would like to be able to do this automatically.

I imagine that this would be done by selecting all shapes and then running the script that changes the formatting of the selected shapes based on the number of incoming lines.

The shapes are irregular, the lines can connect on any side, I want to be able to apply the script to any shape. I don't understand your question about the Height and Width boxes?

Thanks for your help!
Johannes, Sweden



Quote:
Originally Posted by DerekAsirvadem View Post
I don't know how to ask this without making your request sound silly, so please forgive me, that is not my intent.

How exactly is the AppleScript module (or whatever code segment is intended to create your shape) supposed to kow how many lines are coming into the shape, or intended to come into the shape ?

Do you want to create a shape (say a simple rectangle), then attach lines to it, then run the script, which re-sizes the shape ... or do you want to tell the script "look, I will have x lines coming in, so create the shape to suit" ?

What about where the lines come in ? Do you only use one side for connection, or can the lines connect to any of the four (or more) sides) ?

Are you wanting this feature for a single shape or to be able to apply it (via exec script) to any shape ?

Are your shapes regular (aligned to grid; size is an integral multiple of Grid/Minor) ... or are they irregular ?

-----

Are you ok with using the Height and Width boxes in the Inspector/Geometry ?

Cheers
 
The basics might look like this, (in which you could experiment with the values, at the top, giving base size and increment per incoming line).

Code:
property pnumBaseSize : 20
property pnumDeltaPerLine : 20

on run
	tell application id "com.omnigroup.OmniGrafflePro"
		tell front canvas of front document
			repeat with oShape in shapes
				my SizeByIncoming(oShape)
			end repeat
		end tell
	end tell
end run

on SizeByIncoming(oShape)
	using terms from application "OmniGraffle Professional 5"
		tell oShape
			set numSize to pnumBaseSize + (pnumDeltaPerLine * (count of incoming lines))
			set size to {numSize, numSize}
		end tell
	end using terms from
end SizeByIncoming
 
Perfect! Thanks a lot!
 
If you only want the resizing to apply to selected shapes, you could rewrite it like this:

Code:
property pnumBaseSize : 20
property pnumDeltaPerLine : 20

on run
	tell application id "com.omnigroup.OmniGrafflePro"
		tell front window
			set lstSeln to selection as list
			repeat with oSeln in lstSeln
				if class of oSeln is shape then my SizeByIncoming(oSeln)
			end repeat
		end tell
	end tell
end run

on SizeByIncoming(oShape)
	tell application id "com.omnigroup.OmniGrafflePro"
		tell oShape
			set oLines to its incoming lines
			set numSize to pnumBaseSize + (pnumDeltaPerLine * (count of oLines))
			set size to {numSize, numSize}
		end tell
	end tell
end SizeByIncoming
 
And, of course, if you want to set the base size to zero, and make the surface area of your shapes directly proportional to the number of incoming lines, you can get a square root in Applescript with an idiom like:

Code:
(count of incoming lines) ^ (1 / 2)
--

Last edited by RobTrew; 2010-10-12 at 07:42 AM..
 
Rob's handled the AppleScript very nicely.

This is the Inspector/Properties/Geometry. What I meant was, are you familiar with (this is important in a large or complex drawing), making changes to one or more shapes together, by changing the values in the Inspector, rather than by dragging the handles.
Attached Thumbnails
Click image for larger version

Name:	PropertiesGeometry.png
Views:	218
Size:	28.5 KB
ID:	1624  
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Searching for script to convert project-based perspective to context one vitvit2002 OmniFocus Extras 0 2013-02-03 11:58 PM
Search-based location contexts stopped working? [A: Google changed results they send; fix incoming.] jdgonzalez OmniFocus for iPhone 9 2012-09-06 09:16 AM
Script: Tree Tool - quick formatting and layout of OG hierarchy diagrams RobTrew OmniGraffle General 16 2012-06-07 12:48 AM
Month-Based Planning with Undetermined Start Date: Formatting and Effort Calculation DavidS OmniPlan General 0 2011-01-02 07:35 AM
Status Checkbox based formatting mlgoodson OmniOutliner 3 for Mac 6 2009-09-23 01:04 AM


All times are GMT -8. The time now is 10:01 AM.


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