Polyline Power14 Nov, 2004 By: Bill Fane Cadalyst
AutoCAD's polylines have some very attractive features -- and they're easy to pick up
Captain LearnCurve had been babysitting his twin grandsons. As he cleaned up after them he was reminded of his grandmother's favorite Bible verse, 1 Corinthians 13:11. "?When I became an adult, I put away childish things."
This month's subject is the polyline, which is not something used by a parrot in a singles bar. The actual AutoCAD command is Pline. The command name and the object it produces are usually pronounced, "p-line," as if one were discussing the queue at a busy washroom.
To see what a polyline is, let's first look at what a regular line is not. When you invoke the Line command, you are asked for a "from" point, and then for a series of "to" points. AutoCAD draws what appears to be a continuous object that wanders across your screen -- but in fact each segment of it is a separate line object with its own start and end point. At the instant you press Enter or Esc to terminate the command, AutoCAD thinks each line was created separately. There is absolutely no relationship between individual line segments; you can Erase or Move each segment individually.
On the other hand, a polyline is what a single run of the Line command appears to be. It is actually a single object with a start and an end. In between it passes through a series of vertices that define each of the "bend" points. If you try to erase one segment, the entire line disappears, much as if you had made a block of a series of individual lines. The polyline can thus be a long, meandering, single object.
So why would you use a polyline instead of a series of regular lines? Well, a polyline has a lot of other interesting properties. For example, it can contain arc segments as well as straight-line segments (figure 1).
Figure 1. A polyline can consist of line and arc segments.
You can give a polyline any desired width (figure 2). This is more powerful and versatile than using lineweight on regular lines. It can thus be used to draw highways, printed circuit board traces, walls, and so on. In fact, the Doughnut (or Donut) command simply draws a polyline consisting of two arc segments with suitable radius and width, each of which spans 180 degrees.
Figure 2. A polyline can have any desired width.
Each polyline segment can have a different start and end width and will taper accordingly (figure 3), so you can draw a river that gets wider as it flows downstream. A segment of a polyline with a specific width at one end and zero width at the other makes a good arrowhead. If the segment is an arc, the arrowhead can curve. If the line has more than one segment, then individual segments can have start or end widths different from the adjoining segments.
Figure 3. Individual polyline segments can have different start and end widths.
The Offset command will offset the entire polyline in one hit, including any width information (figure 4).
Figure 4. The Offset command offsets the entire polyline, including width information.
On top of everything else, a polyline takes the color and line type of the current layer and can be assigned a specific line type or color. You can, for example, have a wide, meandering, dashed line (figure 5). If you want to get really weird, try this with the gas line style.
Figure 5. Polylines can be assigned a line type.
Take Command of Your Polylines
So how do we accomplish all this magic? There are two commands: Polyline (Pline) is used to draw the basic object and set certain characteristics of it on the fly, while PolylineEdit (Pedit) is used to change things later. Actually, you may have already used polylines without realizing it: The Rectangle, Polygon, and Doughnut commands actually produce polylines.
Let's start with the Pline command. As usual with AutoCAD these days, there are at least three ways to start it. You can select Draw / Polyline from the menu, or pick the Polyline button on the Draw toolbar, or type in Pline at the Command prompt.
The first time you invoke it can be a little unnerving. It seem innocuous enough at first -- it just asks for a "from" point -- but when you pick one, it jumps back with a "Current line-width is 0.0" message and a five-choice prompt. The good news is you can just ignore the choices for now and simply pick several "next" points at random.
As usual, the normal AutoCAD point-selection methods apply. You can pick points with the mouse, type in coordinate pairs, indicate a rectangular or polar relative offset -- for example, @2.3, 4.5 -- from the last vertex, or use Direct Distance Entry. All object snaps such as End, Mid, Center, and so on, as well as Ortho or Polar modes, are still active.
When you get tired of this game, just press Enter or Esc to terminate the command.
Now try the Copy and Move commands and see how the polyline behaves like a single object. While you are at it, try the List command to see all the vertex information.
Having drawn a basic polyline, you are now ready to try some of the other choices.
Working with Width
Start the Pline command again and pick a start point. When the multiple prompt appears, let's follow our usual practice of trying the last one first. Enter a W to tell AutoCAD that you want to set the width. You will be asked for a starting width for the next segment. As usual, you can type in a value or pick a distance with the mouse. (More on this below.)
You are now asked for an ending width and offered the starting width as a default. If you accept the default by just pressing Enter, you get a rectangular segment, but if you provide a different value, you get a tapered segment.
You can now carry on to select more vertex points. Each succeeding segment defaults to having a uniform width equal to the ending width of the previous segment, but at any time you can enter a W again and change the width. The ends of each segment are properly beveled, so they meet cleanly at each vertex.
Note also that a width of zero is quite valid, and is the default. It produces a minimum-displayable line just as the Line command does. The current width is also remembered, so if you come back to draw another polyline later, it will default to having the ending width of the last polyline drawn.
Polylines have some interesting properties when you use object snaps to pick them. Each segment behaves as though it were a separate object, so if you snap to the middle or end of a polyline, you get the middle or end of the segment where you picked the line, and not the middle or end of the complete polyline. The width is ignored, so the end of a segment is located at the center of the width. You cannot snap to the intersection of the corners of a wide polyline segment because nothing intersects there.
You may have noticed an odd action if you invoked the Width option and then used your mouse to pick a width: The rubberband stays anchored to the end of the last segment and you only get to pick one point. The width then becomes the distance between this point and the end of the segment.
Quite often, this is not the effect you want, so AutoCAD provides the Halfwidth option. At first, it appears to behave exactly like the normal Width option, but when you type in or pick a distance it is doubled to produce the actual polyline width. This is usually the more useful mode if you are using the mouse to indicate a distance to AutoCAD.
This one behaves exactly like the Undo option in the Line command: It simply backs up one segment.
This option produces a segment of the specified length, continuing in the same direction as the previous segment. Why not just make the previous segment longer, you may ask? Two reasons: You may want a vertex at a specific location so you can snap to it, and extra vertices become very significant when we do curve fitting.
Like the Line command, this causes the end of the last segment to join back to the start of the very first one. Instead of simply drawing a segment back to the end of the starting segment, it is usually better to use Close with a wide polyline because the ends will bevel properly. Curve fitting also behaves better with Close.
If you do not close a polyline and then issue the Area command, AutoCAD calculates the total area as if there were one more imaginary segment from the end back to the start. The perimeter reported, however, will be the actual polyline length without the added imaginary segment.
I have saved the best for last. Your first hit at this function can be a little unnerving because it appears to have a mind of its own. Unlike the normal Arc command, this one defaults to only asking for one point. An arc segment then mysteriously appears with what appears to be a random radius and center location.
Closer examination of the polyline arc and of the AutoCAD help facility reveals that it is not quite as random as it first appears. The arc segment defaults to having a start direction that is tangent to the previous polyline segment, whether it is an arc or straight segment.
The fun begins if you select an arc as the very first segment of the polyline. In this case, the start direction for the arc defaults to being tangent to the last polyline, regular line, or regular arc that was drawn no matter where it is located in the drawing. If there is no previous direction defined, then it defaults to east.
Quite often, the default direction is not what we want. We may want the first arc segment to start in some other direction, or we may want a lump in the line that is not tangent to the preceding or following segment (figure 6). When you invoke the Arc subcommand, AutoCAD brings up a new prompt that offers several choices. The AutoCAD help facility does a good job of explaining what each one does -- and anyway, the choices are generally self-explanatory, so the best approach is to simply go ahead and experiment.
Figure 6. Arc segments do not need to be tangent.
There is one item in the manual that neophytes often overlook, however. An arc segment cannot have an included angle of 360 degrees. If you want to draw a polyline circle, you can either draw two 180-degree arc segments, or you can use the Doughnut command, which does the same thing.
3D or Not 3D?
Polylines are 2D objects in that all segments must lie in a single plane. This can be defined by any arbitrary UCS (user coordinate system), and hence can have any desired 3D orientation within the drawing, but the polyline itself is flat.
If you do want to draw a true 3D polyline -- for example, to draw a spiral staircase or to plot the flight path of a drunken pelican -- you can use the 3Dpoly command. 3D polylines contain straight segments only (no arcs) and can't have width or thickness, but the Pedit command will fit a 3D b-spline curve to the vertices. (Come back next month for more about this.)
I know you never make mistakes, but sometimes the boss comes along and wants some changes. The PolylineEdit command (Pedit) allows us to add, move, and delete vertices. It also allows us to perform curve fitting, to turn regular lines into polylines, and to join polylines into one longer one. It is getting a little late to get into this now, so let's leave it for next month.
If your drawing contains a lot of wide polylines, then Regen and Redraw functions will slow down drastically as AutoCAD has to calculate all the pixels necessary to fill in the lines. If you enter the Fill command and turn it off, then polylines (and dimensioning arrowheads) will display as simple outline frames, which display much faster -- but the screen won't actually change until the next Regen. This also works for quick check plots too; just turn on Fill when you are ready for a final plot.
If the 3D view direction is anything other than a straight-on plan view, then the Fill setting is ignored and polylines display as though Fill is off.
And Now for Something Completely Different
As one grows older, one should become aware of family medical history. For example, if your father and grandfather developed epilepsy in their early 60s, the odds are pretty good that you will too.
"Wait a minute, isn't epilepsy a young person's disease, and don't most people grow out of it by their late 20s?"
Yeah, well, what's your point?