Straightening relationship lines in #PowerDesigner

ER/Studio Data Architect allows you to remove all bends from a relationship symbol:

ER Studio - remove all bends

PowerDesigner has no equivalent, so I’ve just written one, as a demonstration of our ability to add functionality to what is already a great product.

I’ve added a ‘Straighten this line’ command to the contextual menu for individual links – it works in any type of model, on most types of link:

Straighten this line

Here’s an example before running the command:

Straighten this line - before

and afterwards – the line connects the same two points, and the corners have been removed:

Straighten this line - after

Here‘s how I did it

I added a new extension for all model types, which adds the ‘Straighten this line’ command for all symbols based on the ‘Polyline’:

PolylinePolyline menu

Here’s the tricky bit, the code for the method (which includes a set of output commands so you can see what it’s doing in the Script tab of the output window). The code has a few steps:

  • change the line style if necessary
  • If the line has more than just the beginning and end points
    • take a record of the coordinates of the destination point
    • remove all points except the first one
    • adds back the destination point
    • refreshes the diagram
Simples!

Sub %Method%(obj)
‘changes the line style to “normal”, then removes all corners
output obj

if obj.CornerStyle <> “0” then obj.CornerStyle = “0” ‘ set the line style to straight

dim dest_point_X, dest_point_Y, Point_Count, current_point
point_count = obj.ListOfPoints.Count

if point_count > “2” then ‘ line has one or more corners
output ” – Initial points: ” & obj.ListOfPoints.AsText

‘ capture the values held in the destination point
dest_Point_X = obj.ListOfPoints.Item.X
dest_Point_Y = obj.ListOfPoints.Item.Y

current_point = Point_Count-1 ‘so that the first link point is not removed
do until current_point = 0
‘remove the last link point in the collection
obj.ListOfPoints.Remove()
current_point = current_point – 1
loop

‘ add a new destination point
obj.ListOfPoints.AddPoint dest_Point_X, dest_Point_Y

output ” – Replaced by points: ” & obj.ListOfPoints.AsText

‘ Refresh the view
ActiveDiagram.RedrawAllViews
end if

End Sub

Advertisements

5 Responses to “Straightening relationship lines in #PowerDesigner”

  1. Andrey Says:

    In PowerDesigner 16.5 SP3 intermidiate points could also be removed by Ctrl + left mouse button clicking

  2. Eric Bless Says:

    Hi George,

    That is cool that the tool can be customized and extended, but for this specific functionality isn’t that what Right click > Disposition > Horizontal or Vertical do, or the rightmost 2 icons on the Layout toolbar?

    • George McGeachie Says:

      Hello Eric, thanks for responding
      I produced this extension today when I was specifcally asked how to make relationship lines straight, no matter where the entity symbols are on the diagram.
      There are three ways this is different from the standard horizontal/vertical alignment feature:
      1. it doesn’t move the end connectors at all
      2. it changes the line style to the only one that allows us to have lines with no corners
      3. the horizontal / vertical alignment feature only works on links where the joined symbols (e.g. entities) line up horizontally or vertically; this extension works on every link


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s