As an example, this works on 2DPolylines and LWPolylines.
You can only select Polylines on unlocked layers at the selection set prompt.
It then iterates through the selectionset, ignoring any closed polylines and displays a keyword prompt using dynamic mode (you can select with the mouse). It gives the closing error and asks if you would like to close the Polyline Yes or No (default is No). If the answer is Yes it removes the end vertex and closes the polyline.
(defun rh:sammlung_n (o_lst grp / tmp n_lst)
(setq n_lst nil)
(cond ( (and o_lst (= (rem (length o_lst) grp) 0))
(while o_lst
(repeat grp (setq tmp (cons (car o_lst) tmp) o_lst (cdr o_lst)))
(setq n_lst (cons (reverse tmp) n_lst) tmp nil)
);end_while
)
);end_cond
(if n_lst (reverse n_lst))
);end_defun rh:sammlung_n
(defun c:TEST (/ *error* c_doc c_spc sv_lst sv_vals ss cnt ent obj v_lst dst ans)
(defun *error* ( msg )
(if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))
(mapcar 'setvar sv_lst sv_vals)
(if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nOops an Error : " msg " occurred.")))
(princ)
);end_*error*_defun
(setq c_doc (vla-get-activedocument (vlax-get-acad-object))
c_spc (vlax-get-property c_doc (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace))
sv_lst (list 'osmode 'cmdecho 'dynmode 'dynprompt)
sv_vals (mapcar 'getvar sv_lst)
);end_setq
(mapcar 'setvar sv_lst '(0 0 3 1))
(if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))
(vla-startundomark c_doc)
(prompt "\nSelect Polylines : ")
(setq ss (ssget ":L" '((0 . "LWPOLYLINE,POLYLINE"))))
(cond (ss
(repeat (setq cnt (sslength ss))
(setq obj (vlax-ename->vla-object (setq ent (ssname ss (setq cnt (1- cnt))))))
(cond ( (= :vlax-false (vlax-get-property obj 'closed))
(cond ( (= (cdr (assoc 0 (entget ent))) "POLYLINE") (setq v_lst (rh:sammlung_n (vlax-get obj 'coordinates) 3)))
( (= (cdr (assoc 0 (entget ent))) "LWPOLYLINE") (setq v_lst (rh:sammlung_n (vlax-get obj 'coordinates) 2)))
);end_cond
(setq dst (distance (car v_lst) (last v_lst)))
(initget "Yes No")
(setq ans (cond ( (getkword (strcat "Distance Start Pt -> End Pt " (rtos dst 2 4) " Close Polyline : ? [Yes/No] <No>"))) ("No")))
(cond ( (= ans "Yes")
(setq v_lst (reverse (cdr (reverse v_lst))))
(vlax-put obj 'coordinates (apply 'append v_lst))
(vlax-put-property obj 'closed :vlax-true)
)
);end_cond
)
);end_cond
);end_repeat
)
);end_cond
(if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))
(mapcar 'setvar sv_lst sv_vals)
(princ)
);end_defun
I am not one of the robots you're looking for