×
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!
  • Students Click Here

*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

Jobs

Lisp to count polyline verticies

Lisp to count polyline verticies

Lisp to count polyline verticies

(OP)
Can anyone suggest a lisp that counts the number of verticies in a polyline or lwpolyline?

RE: Lisp to count polyline verticies

Try this (I didn't, at home and no AC).
If polyline is closed it will count that as an extra vertex.  It could be fixed with a check of the "closed flag" if you need it.

CODE

(defun c:nvert ()
   (vl-load-com)
   (setq Pl_Ent (car (entsel "\nSelect polyline: ")))
   (setq VL_Obj (vlax-ename->vla-object Pl_Ent))
   (setq endParam (vlax-curve-getEndParam Vl_Obj))
   (setq NumVert (+ 1 endParam))
   (princ (strcat "\n" (rtos NumVert 2 0) " vertices"))
   (princ)
)

RE: Lisp to count polyline verticies

(OP)
Super!  How would I also get the length of the polyline?

RE: Lisp to count polyline verticies

OK, but next one's gonna cost you :)
You might change the "c:nvert" since it does more now.

CODE

;;routine to provide number vertices and length
;;for a single polyline.  And maybe a few other objects
(defun c:nvert ()
   (vl-load-com)
   (setq Pl_Ent (car (entsel "\nSelect polyline: ")))
   (setq VL_Obj (vlax-ename->vla-object Pl_Ent))
   (setq endParam (vlax-curve-getEndParam Vl_Obj))
   (setq NumVert (+ 1 endParam))
   (setq Pl_Len (vlax-curve-getDistAtParam VL_Obj endParam))
   (princ (strcat "\n" (rtos NumVert 2 0) " vertices"))
   (princ (strcat "\nLength= " (rtos Pl_Len)))
   (princ)
)

RE: Lisp to count polyline verticies

(OP)
Great!  Worth all it cost me!!  All I have to do now is modify it so for a closed polyline the number of verticies is decreased by one and for an open polyline the number is decreased by 2 (since I'm only interested in verticies where two line segments intersect).  Then I'll make it plant appropriate text at or near the polyline.  I have got to learn the VBA language - LISP is just not enough!!  Any good reading material you can suggest?

RE: Lisp to count polyline verticies

Those vlax functions are actually part of "Visual Lisp".
Good place to start (& maybe all you'll need) is http://www.afralisp.net/

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources