明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1337|回复: 8

[已解答] 如何获取多重引线的文字的外框大小,或右下角坐标,或行数

[复制链接]
发表于 2015-7-29 11:02 | 显示全部楼层 |阅读模式
多重引线(mld)对齐
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=168655&fromuid=7309019

多重引线的对齐问题通过大师前辈的指点基本上解决了,还是想把间距排列也写进去,统一成一个命令。
构想一:(文本高度+间距),问题是,如何获取文字的外框大小或右下角坐标
构想二:(((文字的大小)*行数)+间距),问题是,如何获取文字的行数

再请大师指点迷津,先谢谢!



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2015-7-31 10:50 | 显示全部楼层
dingtiedt 发表于 2015-7-29 14:11
无意中在G版提供的lee-mac的页面看到了 “string to list”,正符合其中的一个构想,先取得多重引线的多行文 ...

LeeMac的函数可以做到
  1. ;; MLeader Textbox  -  Lee Mac
  2. (defun LM:mleadertextbox ( ent / bpt enx hgt jus lst mat org prp rot wid )
  3.     (if (= acmtextcontent (cdr (assoc 172 (reverse (setq enx (entget ent))))))
  4.         (progn
  5.             (setq prp (list (cons 40 (cdr (assoc 41 enx)))
  6.                             (cons 07 (cdr (assoc 02 (entget (cdr (assoc 340 enx))))))
  7.                       )
  8.                   lst (vl-remove-if 'null
  9.                           (mapcar
  10.                              '(lambda ( str / box )
  11.                                   (if (setq box (textbox (cons (cons 1 str) prp)))
  12.                                       (mapcar '- (cadr box) (car box))
  13.                                   )
  14.                               )
  15.                               (LM:str->lst (cdr (assoc 304 enx)) "\\P")
  16.                           )
  17.                       )
  18.                   bpt (trans (cdr (assoc 12 enx)) 0 (cdr (assoc 11 enx)))
  19.                   rot (cdr (assoc 042 enx))
  20.                   jus (cdr (assoc 171 enx))
  21.                   wid (apply 'max (mapcar 'car lst))
  22.                   hgt (+ (apply '+ (mapcar 'cadr lst)) (* 0.68 (cdr (assoc 45 enx)) (1- (length lst))))
  23.                   org (list (cond ((member jus '(2 5 8)) (/ wid -2.0)) ((member jus '(3 6 9)) (- wid))      (0.0))
  24.                             (cond ((member jus '(1 2 3)) (- hgt))      ((member jus '(4 5 6)) (/ hgt -2.0)) (0.0))
  25.                       )
  26.                   mat (list
  27.                           (list (cos rot) (sin (- rot)) 0.0)
  28.                           (list (sin rot) (cos rot)     0.0)
  29.                          '(0.0 0.0 1.0)
  30.                       )
  31.             )
  32.             (mapcar '(lambda ( p ) (mapcar '+ (mxv mat p) bpt))
  33.                 (list org
  34.                     (mapcar '+ org (list wid   0))
  35.                     (mapcar '+ org (list wid hgt))
  36.                     (mapcar '+ org (list 0   hgt))
  37.                 )
  38.             )
  39.         )
  40.     )
  41. )

  42. ;; String to List  -  Lee Mac
  43. (defun LM:str->lst ( str del / pos )
  44.     (if (setq pos (vl-string-search del str))
  45.         (cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del))
  46.         (list str)
  47.     )
  48. )
  49. (defun mxv ( m v )
  50.     (mapcar '(lambda ( r ) (apply '+ (mapcar '* r v))) m)
  51. )


_$ (setq e (ssget "_+.:E:S" '((0 . "MULTILEADER"))))
(setq e (ssname e 0))
(LM:mleadertextbox e)
<Selection set: 383>
<Entity name: 7ee384f8>
((1920.97 605.151 0.0) (1947.5 605.151 0.0) (1947.5 609.285 0.0) (1920.97 609.285 0.0))
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2015-7-29 14:11 | 显示全部楼层
无意中在G版提供的lee-mac的页面看到了 “string to list”,正符合其中的一个构想,先取得多重引线的多行文字的字符串,再按 "\\" 为界分段取字符串,最后用length求得数目,就是“行数”
  1. ;; String to List  -  Lee Mac
  2. ;; Separates a string using a given delimiter
  3. ;; str - [str] String to process
  4. ;; del - [str] Delimiter by which to separate the string
  5. ;; Returns: [lst] List of strings

  6. (defun LM:str->lst ( str del / len lst pos )
  7.     (setq len (1+ (strlen del)))
  8.     (while (setq pos (vl-string-search del str))
  9.         (setq lst (cons (substr str 1 pos) lst)
  10.               str (substr str (+ pos len))
  11.         )
  12.     )
  13.     (reverse (cons str lst))
  14. )
测试有用
发表于 2015-7-29 14:20 | 显示全部楼层
能不能直接求文字的box呢?
 楼主| 发表于 2015-7-29 14:27 | 显示全部楼层
cable2004 发表于 2015-7-29 14:20
能不能直接求文字的box呢?

textbox好象只对单行文字有效,mtext的dxf里有“43多行文字图元的垂直高度”,多重引线的多行文字的却找不到。
请问你有具体的方法吗?
发表于 2015-7-29 14:57 | 显示全部楼层
水平文字可以(vla-GetBoundingBox (vlax-ename->vla-object obj) 'Minp 'Maxp)
 楼主| 发表于 2015-7-30 12:43 | 显示全部楼层
cable2004 发表于 2015-7-29 14:57
水平文字可以(vla-GetBoundingBox (vlax-ename->vla-object obj) 'Minp 'Maxp)

谢谢你的回复。用这个测试了一下,得到的坐标是整个多重引线的左下角点和右上角,是不是用这个方法也能得到多重引线中的文字的坐标?
 楼主| 发表于 2015-7-31 14:37 | 显示全部楼层
lucas_3333 发表于 2015-7-31 10:50
LeeMac的函数可以做到

太好了,谢谢你解囊相助!

点评

问题解决了,就置为已解决吧, 有努力就一定会成功! 期待你的成功!  发表于 2015-7-31 15:48
发表于 2019-4-11 18:09 | 显示全部楼层
你好,这个LM函数的代码是怎么用到CAD里边的?直接加载然后输入什么命令?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-13 03:28 , Processed in 0.193026 second(s), 36 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表