No More Drudgery (From the Trenches AutoCAD Tutorial)

31 Jul, 2007 By: Salvatore Napolitano

Write your own VBA code for AutoCAD to draft underground ductile iron pipe.

There's no easy way to draft underground ductile iron pipelines for water and wastewater. Anyone who has drafted single-line ductile iron pipe knows that it's very laborious. Why is it difficult to draft ductile iron pipe and why does Visual Basic offer a good solution?

Ductile Iron Pipe Layout Rules
If you want to draft a pipeline that can be constructed by a contractor as designed, you must pay attention to both bends and deflections. Bends are the fittings used to change direction and they are at 90-, 45-, 22 1/2-, and 11 1/4-degree angles. Each pipe joint can be deflected by 2-8 degrees depending on the pipe diameter and joint type. For example, a 6" pipe with push-on-joint can be deflected as much as 5 degrees, and the same pipe diameter with a mechanical joint can be deflected as much as 7 degrees. DIPRA provides tables where you can look up the allowable deflection as shown below. Although, you don't want to be referring to tables while drafting!

When needed, you can look up deflection information in table, although you don't want to do this all the time while you're busy drafting.

Free Software?
We often draft many miles of pipeline, sometimes as many as 11 miles, and a program to help us would be very handy. Before writing a program, we searched for free programs first. Vaultic offers 2D and a 3D piping software, but the software doesn't consider bends and deflections. It uses a multiline for 2D piping, but we typically use a single line to represent the pipe and again there is no consideration for angles. The Vaultic software does have a multitude of 3D fittings that were very impressive if your company's mechanical department does not want to redraw hundreds of fittings.

Pick a Programming Language
When I found that there wasn't anything available, I set out to write my own program.

I knew I needed a dialog box so the user could have a drop-down list of only valid pipe sizes that vary with the pipe joint selected. The problem was I knew AutoLISP for AutoCAD, but I never bothered to learn Visual LISP or dialog control language (DCL) for dialog box interfacing. I certainly didn't know Visual Basic for Applications (VBA). In searching for a book to learn DCL for AutoLISP, I read two Cadalyst articles that convinced me to learn VBA rather than DCL:

Basically, the authors explained DCL programming was cumbersome and used only in CAD. VBA for AutoCAD was much more convenient for dialog boxes (a main goal), and VBA is used in many Windows applications, making it a valuable tool to learn.

Learning VBA
Rather than teach myself DCL, I decided to learn VBA. The customer reviews raved about Joe Sutphin's book, "AutoCAD 2006: a Programmer's Reference," published by Apress. I became familiar with the language with this book, but I could not program after reading it. The fact that it is a reference should have been a clue that it was not a teaching book. For my next step, I ordered "Using Visual BASIC with AutoCAD 2002" by Andrew Roe, a Thompson Learning Autodesk Press book. This book was like taking a class. Believe me, if you read this book you can program in VBA also!

Programming Tips
This was the information I needed to tackle developing a ductile iron pipe program with dialog boxes. The biggest surprise for me was that I was missing all the AutoLISP geometry functions. When you do your own programming, you'll need to develop your own functions such as the one shown below to find the distance between two points.

Public Function DistPtPt(PT1 As Variant, PT2 As Variant) As Double
 DistPtPt = Sqr((PT2(0) - PT1(0)) ^ 2 + (PT2(1) - PT1(1)) ^ 2)
End Function

Be sure that your program draws lines at exact bends to the previous lines. Your program should then prompt you to Undo the last line or Deflect the last line to a maximum allowable limit based on the pipe size and fitting type. Study the flow chart below for details on programming decisions you'll need to make. There are a lot of geometry and angles, but it's well worth the drafting-time savings.

Keep in mind that there are numerous advantages to building your own VBA program:

  • The program will pay for itself very quickly because it will cut drafting time significantly.
  • The program will eliminate drafting errors in bend and deflection angles and in turn will reduce construction problems.
  • You can always append the program to do more, such as automatic text labels, quantity takeoff, and offsets off of curb lines and fire hydrants.

I haven't added any enhancements yet, but using my basic program definitely takes the drudgery out drafting ductile iron pipe. Click here to download additional samples to help you write this handy program.

When developing your own VBA program, follow this decision tree.

About the Author: Salvatore Napolitano

More News and Resources from Cadalyst Partners

For Mold Designers! Cadalyst has an area of our site focused on technologies and resources specific to the mold design professional. Sponsored by Siemens NX.  Visit the Equipped Mold Designer here!

For Architects! Cadalyst has an area of our site focused on technologies and resources specific to the building design professional. Sponsored by HP.  Visit the Equipped Architect here!