m4rdy 发表于 2022-7-5 19:43:29

从S查找最近的文字/多行文字

大家好,
如何从指定点找到最近的指定文字/多行文字对象?
例如:我想找到距离点A最近的TB2A。
非常感谢。
 
马尔迪
 

Lee Mac 发表于 2022-7-5 19:56:03

快速书写:
 
(defun NearestTextFromPoint ( pt str / d e i l m r s )
   (if
       (setq s
         (ssget "_X"
               (list
                  '(0 . "TEXT,MTEXT")
                   (cons 1 str)
                   (cons 410 (if (= 1 (getvar 'CVPORT)) (getvar 'CTAB) "Model"))
               )
         )
       )
       (repeat (setq i (sslength s))
         (setq e (ssname s (setq i (1- i)))
               l (entget e)
         )
         (if
               (<
                   (setq d
                     (distance pt
                           (if
                               (or (eq "MTEXT" (cdr (assoc 0 l)))
                                 (and
                                       (zerop (cdr (assoc 72 l)))
                                       (zerop (cdr (assoc 73 l)))
                                 )
                               )
                               (cdr (assoc 10 l))
                               (cdr (assoc 11 l))
                           )
                     )
                   )
                   (cond (m) ((1+ d)))
               )
               (setq m d r e) r
         )
       )
   )
)

(defun c:test ( / s p )
   (setq s (getstring t "\nString: "))
   (if (setq p (getpoint "\nPoint: "))
       (sssetfirst nil (ssadd (NearestTextFromPoint (trans p 1 0) s)))
   )
   (princ)
)

wimal 发表于 2022-7-5 20:02:32

 
我测试了一下,效果很好

Lee Mac 发表于 2022-7-5 20:04:17

很高兴听到维马尔

Dadgad 发表于 2022-7-5 20:15:48

 
对《密码大师》的微弱赞扬。
也许应该向你道谢?

m4rdy 发表于 2022-7-5 20:22:20

谢谢你,李,这对我的快速测试有效。我还在学习你的日常生活。。。。
 
马尔迪

orange 发表于 2022-7-5 20:28:41

很抱歉回复了一条旧帖子。我也需要这个,但在选择一个点后,得到了这个错误:“点:;错误:错误的参数类型:lentyp nil”

Lee Mac 发表于 2022-7-5 20:35:26

 
更改:
(defun c:test ( / s p )
   (setq s (getstring t "\nString: "))
   (if (setq p (getpoint "\nPoint: "))
       (sssetfirst nil (ssadd (NearestTextFromPoint (trans p 1 0) s)))
   )
   (princ)
)
收件人:
(defun c:test ( / e s p )
   (setq s (getstring t "\nString: "))
   (if (setq p (getpoint "\nPoint: "))
       (if (setq e (NearestTextFromPoint (trans p 1 0) s))
         (sssetfirst nil (ssadd e))
         (princ (strcat "\nNo text/mtext with content \"" s "\" found in the current layout."))
       )
   )
   (princ)
)

orange 发表于 2022-7-5 20:42:53

谢谢李,效果很好!嗯,你能修改一下吗,这样它就能找到最近的文本了?编辑:没关系,它可以使用通配符。

Lee Mac 发表于 2022-7-5 20:46:39

不客气。
页: [1]
查看完整版本: 从S查找最近的文字/多行文字