The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniGraffle General (http://forums.omnigroup.com/forumdisplay.php?f=10)
-   -   Script for formatting size based on incoming lines (http://forums.omnigroup.com/showthread.php?t=18395)

muntzing 2010-10-06 11:33 PM

Script for formatting size based on incoming lines
 
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

DerekAsirvadem 2010-10-11 11:12 PM

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

muntzing 2010-10-12 03:27 AM

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=DerekAsirvadem;87280]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[/QUOTE]

RobTrew 2010-10-12 04:34 AM

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[/CODE]

muntzing 2010-10-12 04:39 AM

Perfect! Thanks a lot!

RobTrew 2010-10-12 04:43 AM

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[/CODE]

RobTrew 2010-10-12 05:36 AM

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)[/CODE]

[COLOR="White"]--[/COLOR]

DerekAsirvadem 2010-10-14 06:28 AM

1 Attachment(s)
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.


All times are GMT -8. The time now is 02:53 AM.

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