Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Closing a polyline

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Anonymous
12991 Views, 4 Replies

Closing a polyline

Depending on the shape of  polyline, the Close command in PEDIT will close the polyline with and arc or with a line.

 

Is it possible to always close the polyline with a line (not and arc, no matter what the polyline looks like)?

 

Also, it seems that given the same polyline, the result of closing using the PEDIT is different than using the property bar close path. Is this normal?

 

(Using Autocad 2014)

4 REPLIES 4
Message 2 of 5
Kent1Cooper
in reply to: Anonymous

Welcome to these Forums!

 

I can't explain that behavior, though there is a certain predictability about it, most of the time.  When you draw one that ends with an arc segment without closing it, the final vertex's bulge factor entry in entity data seems to be the complement of the last segment [the factor that gives the rest of the circle of which that arc segment is a part], so when you close it in the Properties box, the closing arc segment has that bulge factor.  And when you do it with PEDIT, it closes with an arc segment that's a tangent continuation, as it would be if you had used the CLose option in drawing it.  But not always -- it seems to be affected by editing.  For instance, if you draw one closed with a line segment but with the last segment before that being an arc, and then un-close it in Properties, its final-vertex bulge factor remains 0.0 as it was for the original closing line segment, so if you close it again [in Properties, not via PEDIT], it will close with a line segment again.  Or if you drag a grip on that last arc segment, it seems the bulge factor for the last vertex doesn't end up with the same relationship to that of the last segment.  Or if you build a Polyline by PEDIT-Joining some Lines and Arcs, then even if the last resulting segment is an arc, closing in Properties will be with a line segment.

 

But here's a simple [minimally tested] routine to do it with a line segment regardless of initial conditions or subsequent editing:

 

(vl-load-com); if needed
(defun C:PLCL ; = PolyLine Close, always with Line segment
  (/ plsel pl)
  (if
    (and
      (setq plsel (entsel "\nSelect open Polyline to close with line segment: "))
      (setq pl (car plsel))
      (= (cdr (assoc 0 (entget pl))) "LWPOLYLINE")
      (not (vlax-curve-isClosed pl))
    ); and
    (command ; then
      "_.line" (vlax-curve-getStartPoint pl) (vlax-curve-getEndPoint pl) ""
      "_.pedit" pl "_join" (entlast) "" ""
    ); command
    (prompt "\nNot an open lightweight Polyline."); else
  ); if
  (princ)
); defun

With a little more code, it could be made to allow "heavy" 2D Polylines, but would need to forbid 3D ones under this approach, because even though PEDIT offers the Join option for them, for some reason it seems you can't join a Line to one.

 

Kent Cooper, AIA
Message 3 of 5
Anonymous
in reply to: Kent1Cooper

Thank you, works very well.

I wonder if is possible to extend it so multiple polylines can be selected and closed in the same way with a line.

Message 4 of 5
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

Thank you, works very well.

I wonder if is possible to extend it so multiple polylines can be selected and closed in the same way with a line.


Certainly.  Give this a shot [again, minimally tested, and it could be enhanced in several ways]:

 

(vl-load-com); if needed
(defun C:PLCL ; = PolyLine(s) Close, always with Line segment
  (/ ss n pl)
  (prompt "\nTo Close open Polylines, always with line segments,")
  (if (setq ss (ssget "_:L" '((0 . "LWPOLYLINE"))))
    (repeat (setq n (sslength ss))
      (setq pl (ssname ss (setq n (1- n))))
      (if (not (vlax-curve-isClosed pl))
        (command ; then
          "_.line" (vlax-curve-getStartPoint pl) (vlax-curve-getEndPoint pl) ""
          "_.pedit" pl "_join" (entlast) "" ""
        ); command
      ); if
    ); repeat
  ); if
  (princ)
); defun
Kent Cooper, AIA
Message 5 of 5
Anonymous
in reply to: Kent1Cooper

Thank you, it is exactly what I needed.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report