Jump to content

List of coordinate with nearest text


RepCad

Recommended Posts

Hi all, 

I need a code to create list from coordinate of each point with nearest text, 

 

1873851371_Screenshot(1016).thumb.png.993f2b732fb40dfe806cf390b86899df.png

 

for example = ((x y BN6) (x y TS5) (x y B1) (x y B2))

x,y is coordinate of each point.

 

Can someone help me??

Thanks in advanced.

Point.dwg

Edited by amir0914
Link to comment
Share on other sites

Command PCTT

(print_out can be adapted, for example more decimal precision, I'm not sure what you want with the result)


(defun print_out (lst / a)
  (foreach a lst
    (princ "\n")
    (princ a)
  )
)

;;  Point Closest To Text
(defun c:pctt ( / points texts i j pt ind dst d result)

  (setq points (ssget "_X" (list (cons 0 "POINT"))))
  (setq texts  (ssget "_X" (list (cons 0 "MTEXT,TEXT"))))
 
  (setq i 0)
  (setq result (list))
  (repeat (sslength points)
    (setq j 0)
    (setq dst nil)  ;; this will hold the closest distance.  If a new closer distance 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))
    )
    
    (setq result (append result (list
      (list
        (nth 0 pt)                                    ;; x value of point
        (nth 1 pt)                                    ;; y value of point
        (cdr (assoc 1 (entget (ssname texts ind))))   ;; text
      )
    )))
    
    (setq i (+ i 1))
  )
 
  (print_out result)
  (princ )
 
)
Edited by Emmanuel Delay
  • Like 1
Link to comment
Share on other sites

Weird, I tried it on your dwg attachment, it works on my pc.

Did you try it on that dwg? Maybe there's something different with the dwg you really want to use it on

 

  • Like 1
Link to comment
Share on other sites

Sorry,  I was running it on another file, I again tested it and works well, thanks a lot.🌹

Edited by amir0914
  • Like 1
Link to comment
Share on other sites

On ‎5‎/‎23‎/‎2019 at 3:45 PM, Emmanuel Delay said:
 
On 5/23/2019 at 3:45 PM, Emmanuel Delay said:

Command PCTT

...

 

Suggestions:

 

Quote
 

...
(setq ind nil)    
(setq pt (cdr (assoc 10
        (entget (ssname points i)))))          ;; Move this here         
(repeat (sslength texts)
 (setq d (distance

           pt                                     ;; From here
   (cdr (assoc 10 (entget (ssname texts j))))
 ))
...                          
(setq result (cons (list                         ;; ucs cons instead of append
      (lisT
        (nth 0 pt)                                        
        (nth 1 pt)                                        
        (cdr (assoc 1 (entget (ssname texts ind))))       
      )
    ) result ))
(ssdel  (ssname texts ind) texts)                ;; to exclude TEXT that is already paired on the next loop
(setq i (+ i 1))
...
 

 

Edited by pBe
  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...