i want to close a selected polyline without clicking or picking a point
(defun C:SWPOLY (/ dat c elst wid ename pend pt)
(vl-load-com)
(setvar "cmdecho" 0)
(setq plw (getvar "plinewid"))
(if
(and (setq dat (entsel "\nSelect source polyline: "))
(wcmatch (cdadr (setq elst (entget (setq ename (car dat)))))
"*POLYLINE*"))
(progn
(setq wid (cdr (assoc 40 elst)))
(prompt (strcat "\nWidth is " (rtos wid)))
(setq pend (osnap (cadr dat) "_end"))
(setq pt
(cond
((equal (vlax-curve-getstartpoint ename) pend 0.0001)
(vlax-curve-getstartpoint ename))
((equal (vlax-curve-getendpoint ename) pend 0.0001)
(vlax-curve-getendpoint ename))
(t nil)))
(if pt
(setq p pt)
(setq p (getpoint "\nSpecify start point: ")))
(command "_.pline" p "_w" wid wid)
(while (eq 1 (logand 1 (getvar "cmdactive")))
(command pause))
(if
(and pt (wcmatch (cdadr (entget (entlast))) "*POLYLINE*"))
(command "_.pedit" ename "_j" (entlast) "" "")))
(prompt "\nNot a polyline"))
(if plw
(setvar "plinewid" plw))
(setvar "cmdecho" 1)
(princ))
(princ)
This should be enough for working with regular polylines (not old-heavy)
(defun c:CPL ( / ss) (if (setq ss (ssget '((0 . "LWPOLYLINE") (-4 . "<NOT") (-4 . "&") (70 . 1) (-4 . "NOT>")))) (command "_.PEDIT" "_M" ss "" "_Close" "")) (princ) )
@john.uhden, posted suggestion does not work with heavy polylines just because I said so... but I can say something else...
(defun c:PLC ( / ss) (if (setq ss (ssget '((0 . "*POLYLINE") (-4 . "<NOT") (-4 . "&") (70 . 1) (-4 . "NOT>")))) (command "_.PEDIT" "_M" ss "" "_Close" "")) (princ) )
Well, now I am saying this will work for both.
@Anonymous wrote:
...try another one or try to modify the lisp i upload
Agent, you're being funny, right? I will definitely not!
It's not me why the suggestion does not solve your issue. I've wrote the routine according your requirements - exactly right.
I can help only if you fully describe your issue. Just words are usually not enough. You should ALWAYS attach a DWG example with both states before and after. It not just helps us better understand your issue but also allows us to test oure code.
@ВeekeeCZ wrote:
....
It's not me why the suggestion does not solve your issue. I've wrote the routine according your requirements - exactly right. ....
On the assumption that this was meant to be something like "It's not clear to me why...", the other thread linked to in Post 5 was clearer about why, but for some reason it's not accessible any more. They wanted something to add a segment returning to the beginning of the Polyline, by adding a final ending vertex at the same place as the starting vertex, but without "closing" it by AutoCAD's definition. If you know that, Posts 9 & 11 make more sense than if you don't.
At least two of us asked why one would want to do that [no response], and I even posted a little routine that would do it, in which I called it "fake closing" the Polyline. It involved going into PEDIT and its Edit-vertex mode, moving around to the end, and Inserting another vertex, at the starting vertex location. I didn't keep the code, and since that other thread is unavailable, I can't get it from there -- if that thread becomes available again, you can find it if you have a use for such a thing. If @Anonymous will explain why that way of closing is preferred over "true" closing, and if the reasoning seems valid, I can certainly come up with an equivalent routine again.
For the record, I believe that a polyline whose last vertex happens to be at its first IS NOT CLOSED. It is closed only if its 'closed property (or 70 code) says it's closed. You have had some of the wisest AutoLispers in the world try to help you. I guess if you think you are wiser than they, then you have no need to be asking for help. Please fix your 'tude, dude.
John F. Uhden
Sorry Agent, still don't understand the issue. You should have post a DWG and no... Whatever.
But here it is, my last TRY! It's closed as hard as I can imagine.
(vl-load-com) (defun c:PLClose ( / ss i en ed p1) (if (setq ss (ssget "_:L" '((0 . "LWPOLYLINE")))) (repeat (setq i (sslength ss)) (setq en (ssname ss (setq i (1- i))) ed (entget en)) (if (not (equal (setq p1 (vlax-curve-getStartPoint en)) (vlax-curve-getEndPoint en) 1e-4)) (entmod (append (subst (cons 90 (1+ (cdr (assoc 90 ed)))) (assoc 90 ed) ed) (list (cons 10 p1) '(40 . 0.0) '(41 . 0.0) '(42 . 0.0) ))))) (vlax-put (vlax-ename->vla-object en) 'Closed -1)) ;; suggested by John Uhden (princ) )
@ВeekeeCZ wrote:
....
But here it is, my last TRY! It's closed as hard as I can imagine.
....
My impression from the other thread was different, but again, it's not accessible now. While it still was, I didn't see any response from the OP to my routine [which took a different approach to a similar result], so I don't know whether it did what they wanted. I had the impression that the adding of a last vertex at the same place as the first one was the goal, to "close" it only visibly, but that they would want to omit your "actual" closing at the end of yours. They would have to confirm whether my impression was correct.
I am shocked by your including that (vlax-put ... 'closed ...) line. I have been under the impression that Agent wanted it to only "appear" closed, which you have done (without that line).
John F. Uhden
That's against my religion ...as you've said before...
Well, last line could be removed... although I'm a little worried about the last parenthesis.
I didn't say the "last" line (did I)?
Oh, go ahead. That will give the OP a chance to create another thread to get it fixed.
John F. Uhden
here is the lisp im talking about but can you modify it.
i want to remove the "specify a point to add a LWPOLYLINE command and make automatic searching the end of polyline and close it according to this lisp"
thank you.
(defun c:test (/ p s e lst)
(if (and (setq p (getpoint "\nSpecify a point to add to LWpolyline :"))
(setq s (car (entsel "\nSelect Unclosed LWpolyline :")))
)
(cond ((not ( = (cdr (assoc 0 (setq e (entget s)))) "LWPOLYLINE"))
(alert "Selected object is not a LWPolyline <!>")
)
((not ( = (cdr (assoc 70 e)) 0))
(alert "Select LWPolyline is closed <!>")
)
(t
(setq lst
(append
(list p)
(mapcar 'cdr
(vl-remove-if-not '(lambda (q) (eq (car q) 10)) e)
)
)
)
(if (entmakex
(append (list '(0 . "LWPOLYLINE")
'(100 . "AcDbEntity")
'(100 . "AcDbPolyline")
(if (assoc 62 e)
(assoc 62 e)
'(62 . 256)
)
(cons 90 (length lst))
'(70 . 1)
)
(mapcar '(lambda (pt) (cons 10 pt)) lst)
(vl-remove-if-not
'(lambda (x) (member (car x) '(6 8 370)))
e
)
)
)
(entdel s)
)
)
)
)
(princ)
)(vl-load-com)
For the record, I believe that a polyline whose last vertex happens to be at its first IS NOT CLOSED. It is closed only if its 'closed property (or 70 code) says it's closed.
I agree with that.
It's hard to explain to some users why using Osnap to pick the first point of a closed object, doesn't get you a "closed" polyline. When in fact it appears (to a human) to be "closed". AutoCAD should be intelligent enough to recognize what the user is doing and properly "close" the polyline and remove the duplicate vertex in this case.
On the other hand, both true closed and fake closed polylines work in most cases when doing something like measuring area, or hatching. Some 3rd party tools though will specifically check for that closed flag and reject it, if not present.
Can't find what you're looking for? Ask the community or share your knowledge.