AutoCAD

No More Drudgery (From the Trenches AutoCAD Tutorial)

1 Aug, 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!

figure
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.

'FUNCTION: DIST BETWEEN TWO POINTS USING
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.

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


About the Author: Salvatore Napolitano


AutoCAD Tips!

Lynn Allen

Autodesk Technical Evangelist Lynn Allen guides you through a different AutoCAD feature in every edition of her popular "Circles and Lines" tutorial series. For even more AutoCAD how-to, check out Lynn's quick tips in the Cadalyst Video Gallery. Subscribe to Cadalyst's Tips & Tricks Tuesdays free e-newsletter and we'll notify you every time a new video tip is available. All exclusively from Cadalyst!
Follow Lynn on Twitter Follow Lynn on Twitter


Latest News from Cadalyst Partners
Feed
Big Hearty Autodesk Welcome to Tinkercad   19 May, 2013

Autodesk announced yesterday at Maker Faire which is essentially the center of the universe event for DIY & Makers our intent to acquire Tinkercad....More>>Read all Between the Lines blog posts>>

Feed
Teaching Old Designs New Tricks   17 May, 2013

Question: What do the QWERTY keyboard, the railroad, and shoelaces have in common? Answer: Their inventors are long gone. The QWERTY keyboard was...More>>Read more PTC Creo blog posts>>

Feed
Ideate - Ideate BIMLink for Revit 2014 now available   17 May, 2013

An update for my favorite Revit tool and most favorite Autodesk reseller. I miss you Bob! ...More>>Read more BIMbuilder blog posts>>

Feed
Discover and Fix Your Vibration Vulnerability with SolidWorks Simulation   17 May, 2013

When I go biking during the summer, I rely on the frame of my bicycle to withstand stresses such as vibration and impact. As I speed down the trail,...More>>Read more SolidWorks Blog posts>>

Feed
Behind the Design: How Words and Sketches Become a Picture Book   18 May, 2013

I bet, next to those dusty engineering and design textbooks on the shelf, you have a few picture books that have led to endless inspiration since you...More>>Read more SolidSmack blog posts>>

Poll
What type of input device (besides the keyboard) do you use at your primary CAD workstation?
Standard mouse
Trackball mouse
Programmable mouse
3D navigation device
Pen/tablet
Multiple devices
Submit Vote




Considering Wide Format Printing Solutions?
Four FREE White Papers Available:






Subscribe Cadalyst Newsletters