Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Lisp to count polyline verticies 1

Status
Not open for further replies.

IFRs

Petroleum
Nov 22, 2002
4,658
Can anyone suggest a lisp that counts the number of verticies in a polyline or lwpolyline?
 
Replies continue below

Recommended for you

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)
)
 
Super! How would I also get the length of the polyline?
 
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)
)
 
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?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor