×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

AutoLisp Tricks

NextVertex - a Lisp trick to access successive vertices of entity (assoc 10 EDDY) by tigrek
Posted: 14 Aug 01

;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

Back to Autodesk: AutoCAD FAQ Index
Back to Autodesk: AutoCAD Forum


My Archive


News


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close