Jump to content

change layer to layer of neares text


nano

Recommended Posts


 (vl-load-com)

;; ALNT (for Assign Lines Nearest Text)
(defun c:ALNT ( / ss i pt1 pt2 dst lines texts ent tp l txt ind)
  (setq ss (ssget (list (cons 0  "TEXT,LINE,LWPOLYLINE,POLYLINE") ) ))
  (setq
    lines (list)
    texts (list)
  )
  (setq i 0)
  (repeat (sslength ss)
    (setq ent (ssname ss i ))
    (setq tp (cdr (assoc 0 (entget ent))))
    (cond
      ((= tp "TEXT")
        (setq texts (append texts (list ent)))
      )
      ( (or (= tp "LINE") (= tp "LWPOLYLINE") (= tp "POLYLINE"))
        (setq lines (append lines (list ent)))
      )
    )
    (setq i (+ i 1))
  )
  (foreach l lines
    (setq pt1 (cdr (assoc 10 (entget l))))
    (setq
      i 0
      dst nil
    )
    (foreach txt texts
      (setq pt2 (cdr (assoc 10 (entget txt))))
      (if (or (= dst nil) (< (distance pt1 pt2) dst) ) (progn
        (setq dst (distance pt1 pt2))
        (setq ind i)
      ))
      (setq i (+ i 1))
    )
    (vla-put-layer
      (vlax-ename->vla-object l)
      (vla-get-layer (vlax-ename->vla-object (nth ind texts)))
    )
  )
  (princ)
)

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...