Author Topic: Draw points at end points of lines  (Read 975 times)

0 Members and 1 Guest are viewing this topic.

Coder

  • Swamp Rat
  • Posts: 827
Draw points at end points of lines
« on: August 27, 2020, 03:42:19 PM »
Hello everyone.

I have polylines and lines objects and I would like to add point objects at the end points of the connected lines and add points to the individual lines as in my screen shot.

I hope its possible to use ssget function because I have many line objects to select.

Thanks in advance.

Dlanor

  • Bull Frog
  • Posts: 263
Re: Draw points at end points of lines
« Reply #1 on: August 27, 2020, 04:32:05 PM »
A basic attempt. You'll have to set pdmode and pdsize. Points will be in current layer.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:lends (/ *error* c_doc c_spc ss cnt ent tlst pt plst)
  2.  
  3.   (defun *error* ( msg )
  4.     (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nOops an Error : " msg " occurred")))
  5.     (princ)
  6.   );end_defun
  7.  
  8.         c_spc (vlax-get-property c_doc (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace))
  9.         ss (ssget '((0 . "LINE,LWPOLYLINE,POLYLINE")))
  10.   );end_setq
  11.  
  12.   (cond (ss
  13.           (repeat (setq cnt (sslength ss))
  14.             (setq ent (ssname ss (setq cnt (1- cnt)))
  15.                   tlst (cons (vlax-curve-getstartpoint ent) tlst)
  16.                   tlst (cons (vlax-curve-getendpoint ent) tlst)
  17.             );end_setq
  18.           );end_repeat
  19.           (while (> (length tlst) 0)
  20.             (setq pt (car tlst) tlst (cdr tlst))
  21.             (if (not (vl-position pt tlst))
  22.               (setq plst (cons pt plst))
  23.               (setq tlst (vl-remove pt tlst))
  24.             )
  25.           );end_while
  26.           (foreach pt plst (vlax-invoke c_spc 'addpoint pt))
  27.         )
  28.         (t (alert "Nothing Selected"))
  29.   );end_cond
  30.  
  31.   (princ)
  32. );end_defun
  33.  

Coder

  • Swamp Rat
  • Posts: 827
Re: Draw points at end points of lines
« Reply #2 on: August 27, 2020, 04:46:11 PM »
Beautiful,

Thank you so much for the codes and for the fast response.