Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

NextVertex - a Lisp trick to access successive vertices of entity (assoc 10 EDDY)

AutoLisp Tricks

NextVertex - a Lisp trick to access successive vertices of entity (assoc 10 EDDY)

by  tigrek  Posted    (Edited  )
;NextVertex - a Lisp trick to access successive vertices of entity (assoc 10 EDDY)
;Inspired by "AutoLisp Question re: Leaders" of chrisj5 of this Forum

;www.homescript.com
;------------------
(defun C:NextVertex()
;Select Objects - for debugging/tutorial - later you drop this
;and call NextVertex1(yourEntity)
;from within your function, with yourEntities from your SelectionSet as argument
;In Lisp tutorials I use this naming convention:
;Suzy for selection set
;Suzilen for number of elements picked
;Sneaky for counter
;EDNA for entity name
;EDDY for full list of entity data
;ShortEDDY for truncated entity list - came into being today, solely for this example.
(setq Suzy (ssget))
(setq Suzilen (sslength Suzy))
(setq Sneaky 0)
(while (< Sneaky Suzilen)
(setq EDNA (ssname Suzy Sneaky))
(setq EDDY (entget EDNA))
(print Sneaky)(Princ "\nEDDY ... ")
(print EDDY)
(setq Sneaky (+ 1 Sneaky))
(NextVertex1 EDDY)
)
)
;-----------------
(defun dxf (n ed) (cdr (assoc n ed)))
;-------------------
(defun NextVertex1(ShortEDDY)
(princ "\nSuccessive access to (Assoc 10 EDDY) ... ")
(while (setq ShortEDDY (member (assoc 10 ShortEDDY) ShortEDDY))
;for debugging
(princ "\n(assoc 10 ShortEddy)..")
(princ (assoc 10 ShortEDDY))
;after debugging, put other function calls here
;to do things with vertex coordinates
;or assign the coordinates to a parameter, to use elsewhere
(setq nextVertexCoords (cdr (assoc 10 ShortEDDY)))
(setq ShortEddy (cdr ShortEddy))
)
(princ)
)
;---------------------

This was for polylines which have all the vertices in one entity list - no SEQUEND there. Multiple (10 xx) appear in the entity list and the lisp above extracts them.

For other entities with SEQUEND, it is all together a different issue, the solution for which, given by Striker is:


You could also show how to access each individual vertice on a complex entity pline, such as a regular polyline or 3dpoly. I personally would do it like this....
ELIST is the entity list of a complex POLYLINE entity

(if (= (cdr (assoc 0 elist)) "POLYLINE")
(while (and elist (/= (cdr (assoc 0 elist))"SEQEND"))
(setq nextvertice (entget (entnext (cdr (assoc -1 elist)))))
(setq vertice_pt (cdr (assoc 10 nextvertice)))
(setq elist (entget entnext))
)
)


Cheers
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search