Lisp to draw 3D points from 2D position and level text

Lisp to draw 3D points from 2D position and level text

dlbsurveysuk
Collaborator Collaborator
1,575 Views
21 Replies
Message 1 of 22

Lisp to draw 3D points from 2D position and level text

dlbsurveysuk
Collaborator
Collaborator

Hi, I've slightly modified some code found here https://www.cadtutor.net/forum/topic/67754-list-of-coordinate-with-nearest-text/ to produce this -

(defun c:pctt ( / points texts i j pt ind dst d result)

  (setq points (ssget "_X" (list (cons 8 "LX"))))
  (setq texts  (ssget "_X" (list (cons 0 "TEXT")))) 
  (setq i 0)
  (setq result (list))

  (repeat (sslength points)
      (setq j 0)
      (setq dst nil)  ;; Closest dist.  If a new closer dist is found we replace dst by that new value
      (setq ind nil)

           (repeat (sslength texts)
               (setq d (distance
                  (setq pt (cdr (assoc 10 (entget (ssname points i)))))            ;; insert point of the point
                  (cdr (assoc 10 (entget (ssname texts j))))                            ;; insert point of the text
         	 	  )
               )

    	    (if (or (= dst nil) (< d dst))
	  	(progn
      	   	  (setq dst d)
      	  	  (setq ind j)
      		)
     	    )
	 
               (setq j (+ j 1))
           );repeat
    
         (setq result (append result (list
            (list
              (nth 0 pt)                                                                                  ;; x value of point
              (nth 1 pt)                                                                                  ;; y value of point
              (atof (cdr (assoc 1 (entget (ssname texts ind)))))                    ;; text to number ?
            )
         )))
    
    (setq i (+ i 1))
  );repeat

         (if result
             (foreach xyzlist result
                   (command "POINT" xyzlist)
                   (princ xyzlist)
             )
         )
(princ )
)

The idea is to draw 3d points at all cross insertions, that have a z value of the nearest text.

Test drawing attached.

 

The command line output shows the correct z values but the drawn points all have z=0.

I can't see what is wrong. I'm sure it's something obvious that I'm missing...

 

Thanks.

0 Likes
Accepted solutions (3)
1,576 Views
21 Replies
Replies (21)
Message 21 of 22

dlbsurveysuk
Collaborator
Collaborator

OK that makes sense now. Thanks again.

0 Likes
Message 22 of 22

komondormrex
Mentor
Mentor

you are welcome)

0 Likes