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

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
current_point = current_point – 1

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

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

‘ Refresh the view
end if

End Sub