Troubleshooting an Infinite Loop: Seeking Assistance to Store Nearest Text to My Block

Troubleshooting an Infinite Loop: Seeking Assistance to Store Nearest Text to My Block

adaptacad
Advocate Advocate
297 Views
2 Replies
Message 1 of 3

Troubleshooting an Infinite Loop: Seeking Assistance to Store Nearest Text to My Block

adaptacad
Advocate
Advocate

Hello everyone, I hope you are all well. Currently, I'm trying to store the text closest to my block in a variable. However, I'm facing an issue with an infinite loop that is preventing the code from functioning correctly. Could someone please help me identify why this loop is occurring? I appreciate any assistance in advance.

 

(defun c:cobrinha ( )
  (defun nmp:maisproximo  (a b c) (< (distance a b) (distance a c)))
  (defun nmp:pegueaoponto ( o ) (cdr (assoc 10 (entget o))))
  
  
  (setq x_selp (ssget (list (cons 0 "INSERT")(cons 8 "ED_POLE"))))
  (setq x_sel (ssget "_X" (list (cons 0 "TEXT")(cons 8 "ED_POLE"))))
  (setq x_lst nil)
  
  (foreach x_ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex x_sel)))
    (setq x_lst (cons (list (nmp:pegueaoponto x_ent) x_ent) x_lst))    
  )
  
  (foreach x_pts (vl-remove-if 'listp (mapcar 'cadr (ssnamex x_selp))) 
    (setq coo (nmp:pegueaoponto (car (vl-remove-if 'listp (mapcar 'cadr (ssnamex x_selp))))))
    (while x_lst
      (setq pnt (car (vl-sort x_lst '(lambda (x y) (nmp:maisproximo coo (car x) (car y))))))
      (setq valor (cdr (assoc 1 (entget (cadr pnt) ))))
    )
  )  
)
  

 

0 Likes
Accepted solutions (1)
298 Views
2 Replies
Replies (2)
Message 2 of 3

ВeekeeCZ
Consultant
Consultant
Accepted solution

(while x_lst.... it shoud work without it.

 

(while x_lst
(setq pnt (car (vl-sort x_lst '(lambda (x y) (nmp:maisproximo coo (car x) (car y))))))
(setq valor (cdr (assoc 1 (entget (cadr pnt) ))))
)

0 Likes
Message 3 of 3

adaptacad
Advocate
Advocate

Resolved, thank you very much!! @ВeekeeCZ 

0 Likes