Message 1 of 22
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
Solved! Go to Solution.