Straighten Line

I received an email recently from a reader who asked how to straighten lines? Given a bunch of lines placed at different angles to one another how would you make them parrallel and all the same length? Something like this.

straighten lines

The interesting bit here isn't how do you straighten the lines (just match end points, remove the original and draw a new line) but how do you determine which line is the template?

From a developer's point of view these are design objectives and not programming issues. In the example I created I decided to use the first line found in the selection set or fence. In reality the designer might need to use any number of lines as the template. In this case you will need to first identify the template line before running the processor. I would call this a business rule, or design rule and it creates a requirement that removes autonomy from the program. In my program I ask, am I processing the first line. If yes, then I save the end points and if no, it means I already have the end points so just process.  In MicroStation VBA (a good way to prototype) it might look like this…

Complete code can be downloaded from the cadgurus page. Filter by MVBA and look for xy_change_vert (

Easy. This means the program is deciding which line to use for me. Notice that this program also provides an option so that the designer can decide which line should be the template. It says if the use first element option is turned off then the program expects to find coordinate values in the form. Another approach might be to build a locate command. In fact this might prove to be better since you won't need to validate the form controls (ie make sure points have been defined).

Homework: Find the source file in the cadgurus archive. Study the locate command and figure out how to eliminate the form. Advanced: Can you validate that the element selected is a line element?

Tags: ,

Leave a Reply

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

You are commenting using your 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

%d bloggers like this: