[code]
hey, guys,here is the code i tried to join polyline as much as possible, then close them, but it just could close one polyline, any idea about this? thank u very much!!! ; this routine is try to join ployline as much as possible, then
; close them.
;;; returns the first group value of an entity.
;;; like the wellknown (dxf) function but accepts all kinds of
;;; entity representations (ename, entget list, entsel list)
(defun GETVAL (grp ele) ;"dxf value" of any ent... (cond ((= (type ele) 'ENAME) ;ENAME (cdr (assoc grp (entget ele)))) ((not ele) nil) ;empty value ((not (listp ele)) nil) ;invalid ele ((= (type (car ele)) 'ENAME) ;entsel-list (cdr (assoc grp (entget (car ele))))) (T (cdr (assoc grp ele))))) ;entget-list ;--------------------------------------------------------------------
;;; (gettyp pline) => "POLYLINE" (defun GETTYP (ele) ;return type
(getval 0 ele)) ;--------------------------------------------------------------------
;;; assure ENAME
;;; convert the entity to type ENAME (defun ENTITY (ele) ;convert to element name (cond ;accepts the following types: ((= (type ele) 'ENAME) ele) ; ENAME ((not (listp ele)) nil) ; error: no list ((= (type (car ele)) 'ENAME) (car ele)) ; entsel-list ((cdr (assoc -1 ele))) ; entget-list or nil ) ) ;--------------------------------------------------------------------
(defun getval (grp ele) (cdr (assoc grp (entget (entity ele))))) ;--------------------------------------------------------------------
;;; (istypep ele "TEXT")
;;; is element a "SOLID"? (defun istypep (ele typ) ;check type
(= (gettyp ele) typ)) ;--------------------------------------------------------------------
;;; (istypep ele '("TEXT" "ATTDEF"))
;;; is element a "TEXT" or a "ATTDEF"? (defun ISTYPEP (ele typ) ;better implementation to accept lists too (cond ((listp typ) (member (gettyp ele) typ)) ((stringp typ) (= (gettyp ele) typ)) ;assume typ uppercase (T nil))) ;--------------------------------------------------------------------
;;; (getpt (entsel)) => ( 0.1 10.0 24) (defun GETPT (ele) ;return the startpoint of any element (getval 10 ele)) ;group 10 ;--------------------------------------------------------------------
;;; (getflag pline) => 1 if closed (defun GETFLAG (ele) (getval 70 ele)) ;same with the entity flag ;--------------------------------------------------------------------
;;; bitvalue val in flag of element set?
;;; (flagsetp 1 pline) => T if closed
(defun FLAGSETP (val ele) (bitsetp val (getflag ele)))
;--------------------------------------------------------------------
;;; (bitsetp 4 12) => T ;bitvalue 4 (=2.Bit) in 12 (=4+8) is set (defun BITSETP (val flag) (= (logand val flag) val))
;--------------------------------------------------------------------
;;; convert selection set to list,
;;; it's to use ai_ssget, because some ents could be on locked layers
;;; (sslist (ai_ssget (ssget))) => list of selected unlocked ents
;;; or (mapcar 'entupd (sslist (ssget "X" '((8 . "TEMP")))))
;;; - regens all entities on layer TEMP (defun SSLIST (ss / n lst) (if (= (type ss) 'PICKSET) (repeat (setq n (sslength ss)) (setq n (1- n) lst (cons (ssname ss n) lst))))) ;--------------------------------------------------------------------
;;; apply a function to each ent in ss,
;;; (ssmap 'entupd (ssget)) ; regenerate only some entities (defun SSMAP (fun ss / n) (if (= 'PICKSET (type ss)) (repeat (setq n (sslength ss)) (apply fun (list (ssname ss (setq n (1- n)))))))) ;--------------------------------------------------------------------
;;; This tries to join as much polylines as possible. (defun C:JOINPOLY (/ ele ss) (foreach ele (sslist (setq ss (ssget))) ;process lists (if (entget ele) ;not already joined (cond ;(then it would be nil) ;((istypep ele '("ARC" "LINE")) ; some pillars might use
; lines or arcs???? ;(command "_PEDIT" ele "_Y" "_J" ss "" ""); convert and JOIN ;) ((and (istypep ele '("POLYLINE" "LWPOLYLINE")) (not (flagsetp 1 ele)) ;not closed
(龙龙仔, my purpose is to join polylines as much as possible, after that, i need to close every polyline, but the aotolisp code below just close only one polyline, u know the "pedit" command for polyline ask "Close" or "Open" all the time, do u have any idea overcome this problem???
;;; This closes as much polylines as possible.
(defun C:CLOSEPOLY (/ ele ss)
(foreach ele (sslist (setq ss (ssget))) ;process lists
(if (and (istypep ele '("POLYLINE" "LWPOLYLINE"))
(not (flagsetp 1 ele)) ;not closed
(vla-object (ssname SS N)))
)
)
(vla-put-closed ENT :vlax-true)
)
(setq N (1+ N))
)
(princ)
)