;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; ;;;; ;;;; Copyright (c) Feb. 1997 by Takehiko Nagakura. ;;;; ;;;; All rights reserved. ;;;; ;;;; ;;;; ;;;; Do not copy, use, modify or distribute this software ;;;; ;;;; without written permission by Nagakura. Nagakura will ;;;; ;;;; not be responsible for any consequence of its use. ;;;; ;;;; ;;;; ;;;; Takehiko Nagakura (e-mail: takehiko@mit.edu) ;;;; ;;;; Massachusetts Institute of Technology ;;;; ;;;; 77 Massachusetts Ave. 10-472M, Cambridge, MA 02139 ;;;; ;;;; ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; Original Feb 21, 1997 by TN ;;;; Last updated March 10, 1999 by TN ; This file provides functions to demonstrate entity data manipulations. ; The program works in AutoCAD R13. ; ; ; function : description ; (c:pline-to-points) ; : prints all point coordinates of pline verteces ; This only deals with a pline made of lines (that is, no arc). (defun c:get-pline-vertices ( / sel ent spt info prim picked all vpt) ; 1) initialize the flag (setq picked nil) ; 2) let user pick a pline and check it is really a pline (while (not picked) (setq sel (entsel "select a pline:")) (setq ent (car sel)) (setq spt (cadr sel)) ; remember the point you clicked for later use (setq info (entget ent)) (setq prim (cdr (assoc 0 info))) (if (equal prim "POLYLINE") (setq picked t) (setq picked nil)) ) ; 3) calls the sub function which does digs the pline data (setq all (pline-vertices ent)) ; 4) bonus is that it orders the point from the end closer to the picked point (if (> (distance (car all) spt) (distance (last all) spt)) (setq all (reverse all))) ; 5) this function returns all points all ) ; When ent is the main data structure of a polyline, this function ; walks through its subentities via "entnext" command and ; find its vertices. The vertices are returned in a list. ; No checking is perforemed as to whether ent is ; actually a POLYOINE (either 2D or 3D). ; In AutoCAD entity database, directly after the pline main entry, ; its vertex points' entity data follows one by one. Thus, you can get ; these point entity data using "entnext" command, which grabs the ; entity data after the specified one. After the last vertex, there ; is another marker entity which flags the end of the pline associated ; entities by "SEQEND" entity type. (defun pline-vertices (ent / ent info prim done all) ; 1) initialize the flag (setq done nil) ; 2) walk through its subentities via entnext command (while (not done) (setq ent (entnext ent)) (setq info (entget ent)) (setq prim (cdr (assoc 0 info))) ; if this is the component vertex, its entity type should be "VERTEX" ; if this is the termination marker, its entity type is "SEQEND" (cond ((equal prim "VERTEX") (setq all (cons (cdr (assoc 10 info)) all))) ((equal prim "SEQEND") (setq done t))) ) (reverse all) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; An updated version which handles pline with arcs. ;; Below is under development. Please polish up the program by yourself. ;; (defun c:zz () (setq my_pl (car (entsel "select a pline:"))) (setq my_v1 (entnext my_pl)) (setq my_v2 (entnext my_v1)) (setq bulge (assoc 42 (entget my_v2))) ) (defun pline-vertex2 (ent1 / info1 ent2 info2 prim1 prim2 done all buldge vert1 vert2 item) (setq done nil) (while (not done) (setq ent1 (entnext ent1)) (setq info1 (entget ent1)) (setq ent2 (entnext ent1)) (setq info2 (entget ent2)) (setq prim1 (cdr (assoc 0 info1))) (setq prim2 (cdr (assoc 0 info2))) (cond ((equal prim2 "SEQEND") (setq done t)) ((equal prim1 "VERTEX") (setq vert1 (cdr (assoc 10 info1))) (setq buldge (cdr (assoc 42 info1))) (setq vert2 (cdr (assoc 10 info2))) (if (= 0.0 buldge) (setq item (list vert1 vert2)) (setq item (list vert1 vert2 bulge))) (setq all (cons item all)) ) (t (print "error in pline-vertex2")) ) ; cond ) ; while (reverse all) )