Align ports and interfaces with a Perl script

The standard EA layout does not support Ports (and Interfaces) with the automatic layout. So you have to do that manually. If you are working with SysML you easily run into a situation where you have loads of Ports on your block and you need to layout these. Here is a little script that helps in the manual layout process.

Port/Interface Layout Assistant

Alignment of ports on a SysML block or a class can be difficult. Especially if your eyes are aged like mine. So I wrote this little script which of course works with my Perl EA Extension published here.

The attached script helps a bit in the layout process by automatically spacing ports evenly in horizontal or vertical order. I developed this script once for interfaces and now improved it for ports. It shall work for any those embedded elements but is currently used by me mainly with ports.

Use cases

Distribute a number of ports evenly on one side of their parent

Once you added embedded ports from the context menu those are placed on the top left side of the parent element with no space. It's quite fiddly to grab the little ports, especially if the labels are in the way and get selected first. Now select the ports and the parent element by dragging the mouse over the top left of the element so all get selected and invoke the addin. I use Alt-A (opens the addins menu), cursor right (selects my Addins list), enter (execute the entry which is the first because I named it "Arrange Ports"). Voilá - all ports are spaced evenly across the top of the element. It's now much easier to move them to the correct order and side.

The above works for all sides. Spacing in horizontal direction is: same space between all selected ports and half the space to left and right of the outer most. For the vertical spacing I check for the stereotype "Block" in which case the spacing is done similarly to the horizontal. For all other elements a fixed spacing for the name compartment is added to the upper space. This is not always optimal, but better than nothing.

Space a number of selected ports evenly

Sometimes you need a group of ports which should have even spacing but not over the whole side of a component. Just move the ports raw to where you want and select them (either ctrl-click or dragging the mouse). The addin will then space all ports inside the two outer ones evenly.

Align "opposite" port

In many cases you have two components placed near to each other with a number of ports connected to the opposite component. Unlike parent elements, the embedded elements cannot be aligned with standard EA drawing tools. So it's always a fiddly piece of work to get these aligned. With this script you simply need to select one of the ports and invoke it. The opposite port will automatically be aligned horizontally or vertically. These are the preconditions: The selected port must have only one connection (visible or invisible) to another port on the diagram. Both ports need to be on either the horizontal or vertical side of their parents.

Align a group of ports with their opponents

First layout the ports of one element by spacing ports over the whole side or as group (see above use cases). Now select one outer most port of this group and perform the Align "opposite" port. Do the same with the other outermost port. Drag the inside ports on the other side roughly to their position so no crossings occur. Select all opposite ports and perform use case: Space a number of selected ports evenly.

Capabilities

There is obviously a large number of "unplanned" usage like multiple elements with multiple embedding on mixed sides and so on. The addin tries to guess which of the selected elements is the "main" parent by the number of selected embedded elements and if necessary the diagram size of those. It will issue complaints on the system output window if needed. But due to the fact that there is a wide range of misuse I cannot promise that all cases are being checked. In the unlikely case that ports/interface get placed "somewhere" on the diagram, just drag them a little bit and EA will drop them back to their parent. I had this during testing but should not occur any more.

Update

As of 30-07-2010 I have uploaded a new release with some error corrections and the capability to align "opposite" ports.

This article contains content available for registered members only. You need to be logged in to view/download this content.

About the Author

Thomas Kilian

Thomas Kilian

Freelancer (Consultant)
Working since mid 1970 in the IT industry. Having gone through development and management in almost all industries (international but based in Germany). Currently focused on UML based projects (Embedded Systems/SysML, SOA, BPM) preferably using EA. And of course customization and CM for EA projects.

Comments

  • Well, not me :-) I could create a DLL from the script as a stand-alone addin.

  • Nice feature, but I will not be allowed to extend EA with PERL for the loads of EA users and installations here. Anyone to translate this into VBScript to run it against EA's scripting engine? Support for ports and interfaces are highly welcomed. Manfred