Draw line between two list of points

Draw line between two list of points

jsaayman
Advocate Advocate
3,472 Views
7 Replies
Message 1 of 8

Draw line between two list of points

jsaayman
Advocate
Advocate

Hi 

 

Is it possible to create a lisp program that will match the two points from a list off points that have the same x and y coordinate and different z coordinates. I want to be able to select all the points at the top and all the points at the bottom and then the program must match the points and draw a line between them.

0 Likes
Accepted solutions (2)
3,473 Views
7 Replies
Replies (7)
Message 2 of 8

marko_ribar
Advisor
Advisor

See if this can help you, I don't have time to test...

 

(defun c:zlines ( / ss i pl pl1 pl2 )
  (while
    (not (setq ss (ssget '((0 . "POINT")))))
    (prompt "\nEmpty sel.set... Reselect all points from both bottom and top positions that overlap in top view...")
  )
  (repeat (setq i (sslength ss))
    (setq pl (cons (cdr (assoc 10 (entget (ssname (setq i (1- i)))))) pl))
  )
  (while (vl-some '(lambda ( x ) (vl-member-if '(lambda ( y ) (if (equal (mapcar '+ '(0 0) x) (mapcar '+ '(0 0) y) 1e-6) (if (< (caddr x) (caddr y)) (setq pl1 (cons x pl1) pl2 (cons y pl2)) (setq pl1 (cons y pl1) pl2 (cons x pl2))))) (vl-remove x pl))) pl)
    (foreach x pl1
      (if (vl-position x pl)
        (setq pl (vl-remove x pl))
      )
    )
  )
  (mapcar '(lambda ( a b ) (entmake '(0 . "LINE") (cons 10 a) (cons 11 b))) pl1 pl2)
  (princ)
)

M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 3 of 8

Kent1Cooper
Consultant
Consultant
Accepted solution

@jsaayman wrote:

.... I want to be able to select all the points at the top and all the points at the bottom and then the program must match the points and draw a line between them.


 

If you're talking about Point entities, here's another way [lightly tested]:

(defun C:LJPVA (/ ptss n ptlist ptA ptB); = Lines Joining Points Vertically Aligned
  (if (setq ptss (ssget '((0 . "POINT"))))
    (progn ; then
      (repeat (setq n (sslength ptss)); make into list of point lists
        (setq ptlist (cons (cdr (assoc 10 (entget (ssname ptss (setq n (1- n)))))) ptlist))
      ); repeat
      (repeat (1- (length ptlist))
        (setq ptA (car ptlist) ptlist (cdr ptlist))
        (foreach ptB ptlist
          (if (equal (list (car ptA) (cadr ptA)) (list (car ptB) (cadr ptB)) 1e-4)
            (command "_.line" "_none" ptA "_none" ptB "")
          ); if
        ); foreach
      ); repeat
    ); progn
  ); if
  (princ)
); defun

It works from one  selection of Point entities resulting in one  list of point locations, not two.  If you have some reason to want to select two separate sets of Points at top and bottom, I assume that can be accommodated, but it's not necessary. 

Kent Cooper, AIA
0 Likes
Message 4 of 8

jsaayman
Advocate
Advocate

@Kent1Cooper Thanks for the reply. I’ll try the code and get back to you. 

0 Likes
Message 5 of 8

marko_ribar
Advisor
Advisor
Accepted solution

You could have checked my code too, and fix those errors...

(defun c:zlines ( / ss i pl pl1 pl2 )
  (while
    (not (setq ss (ssget '((0 . "POINT")))))
    (prompt "\nEmpty sel.set... Reselect all points from both bottom and top positions that overlap in top view...")
  )
  (repeat (setq i (sslength ss))
    (setq pl (cons (cdr (assoc 10 (entget (ssname ss (setq i (1- i)))))) pl))
  )
  (while (vl-some '(lambda ( x ) (vl-member-if '(lambda ( y ) (if (equal (mapcar '+ '(0 0) x) (mapcar '+ '(0 0) y) 1e-6) (if (< (caddr x) (caddr y)) (setq pl1 (cons x pl1) pl2 (cons y pl2)) (setq pl1 (cons y pl1) pl2 (cons x pl2))))) (vl-remove x pl))) pl)
    (foreach x pl1
      (if (vl-position x pl)
        (setq pl (vl-remove x pl))
      )
    )
  )
  (mapcar '(lambda ( a b ) (entmake (list '(0 . "LINE") (cons 10 a) (cons 11 b)))) pl1 pl2)
  (princ)
)
Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 6 of 8

jsaayman
Advocate
Advocate

@marko_ribar sorry I will check yours too. Thank you for the reply.

0 Likes
Message 7 of 8

daniel.valenciaQH2JE
Explorer
Explorer

i have a similar problem, i am trying to draw lines between two consecutive point (it can be consecutive in x or y), but i dont want to have one line over another, do you know how modify your routine for this?

 

Thank you

0 Likes
Message 8 of 8

jsaayman
Advocate
Advocate
Hi. No sorry I don't know how to modify the script to do this. But there
are a lot of intelligent people on the forum that will be able to help you.
0 Likes