;---------------------------------------------------------- ; LWPolyline Utilities ; From 1999 Autodesk University course PR31 ; taught by Bill Kramer ; ; Utilities: ; LWPOLY_SHOW - Given Entity list, prints points in polyline ; LWPOLY_NTH - returns point, bulge, and widths of segment N ; LWPOLY_CHANGE - change nth point, bulge and widths ; LWPOLY_2_POLY - convert a lightweight poly to a ; traditional poly ; ;---------------------------------------------------------- (defun LWPOLY_SHOW (EL) (while (setq EL (member (assoc 10 EL) EL)) (print (cdr (assoc 10 EL))) (setq EL (cdr EL)) ) ) ;;--------------------------------------------------------- ; (defun LWPOLY_NTH (N EL) (setq EL (member (assoc 10 EL) EL)) (while (and EL (> N 0)) (setq EL (member (assoc 10 (cdr EL)) EL) N (1- N) ) ) (if (and EL (zerop N)) (list (assoc 10 EL) (assoc 40 EL) (assoc 41 EL) (assoc 42 EL) ) ) ) ;;--------------------------------------------------------- ; (defun LWPOLY_CHANGE ( EL ;;entity list N ;;position PT ;;new point value NW1 NW2 ;;new width factors NB ;;new bulge factor / EL2 ;;entity list buffer ) ;;loop through lightweight polyline entity list ;;until at the right position. ;; (while (and EL (> N -1)) ;; ;; A point encountered? Decrement the position indicator (if (= (caar EL) 10) (setq N (1- N))) ;; (setq EL2 (cons (car EL) EL2) ;;save in buffer list EL (cdr EL))) ;;reduce entity list and loop ;; ;; Rebuild the entity list ;; (setq EL (cons (cons 10 PT) ;;add 10 point (cons (cons 40 NW1) ;;add 40 width 1 (cons (cons 41 NW2) ;;add 41 width 2 (cons (cons 42 NB) ;;add 42 bulge (cdddr EL)))))) ;;remove 40,41,42 (append (reverse (cdr EL2)) EL) ) ;;--------------------------------------------------------- ; (defun LWPOLY_2_POLY ( EL ;;entity name or list of lightweight polyline / ZV ;;elevation ZT ;;thickness LYR ;;layer name CLR ;;color number LTY ;;line type name ) (if (= (type EL) 'ENAME) ;;check if Entity name supplied (setq EL (entget EL)) ;;convert to entity list (if (= (type (car EL)) 'ENAME) ;; (entsel) pick supplied? (setq EL (entget (car EL))))) ;;convert to entity list (if (= (cdr (assoc 0 EL)) "LWPOLYLINE") ;;is it proper? (progn (setq ZV (assoc 38 EL) ;;get the elevation ZT (assoc 39 EL) ;;and thickness CLR (assoc 62 EL) ;;and color LTY (assoc 6 EL) ;;and line type ) ;;These values will be nil if not found in the list. (if (null ZV) (setq ZV 0.0)) ;;correct nil entries (if (null ZT) (setq ZT 0.0)) (setq EN (list ;;create header object list '(0 . "POLYLINE") (setq LYR (assoc 8 EL)) (assoc 210 EL) ;;use data from lightweight polyline ZT (list 10 0.0 0.0 (cdr ZV)) (assoc 70 EL) )) (if CLR (setq EN (append EN (list CLR)))) (if LTY (setq EN (append EN (list LTY)))) (entmake EN) ;;create the polyline header ;; (setq EN (list ;;create a data list for a vertex '(0 . "VERTEX") LYR '(10 0 0 0) ;;we will substitute these values '(40 . 0.0) ;;in the loop below for the actual '(41 . 0.0) ;;points and arcs desired. '(42 . 0.0) ZT )) (if CLR (setq EN (append EN (list CLR)))) (if LTY (setq EN (append EN (list LTY)))) ;; ;; Loop through the entity list getting each point ;; starting with a group code 10. ;; (while (setq EL (member (assoc 10 EL) EL)) ;; ;; Substitute the group codes, add the Z when going ;; when going from a 2D polyline to 3D. ;; (setq EN (subst (append (assoc 10 EL) (list (cdr ZV))) (assoc 10 EN) EN) EN (subst (assoc 42 EL) (assoc 42 EN) EN) EN (subst (assoc 40 EL) (assoc 40 EN) EN) EN (subst (assoc 41 EL) (assoc 41 EN) EN) ) ;; Create the entity object for the vertex. (entmake EN) (setq EL (cdr EL)) ;;remove the group code 10 ) ;;finish the polyline object with the SEQEND object (entmake (list '(0 . "SEQEND") LYR)) ;; ;; Return the entity name of the polyline object just ;; created. ;; (entlast) ) ) ;;else return nil. )