乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
楼主: vernonlee

[编程交流] 帮助:更改的文本长度

[复制链接]

5

主题

1074

帖子

1088

银币

初来乍到

Rank: 1

铜币
9
发表于 2022-7-5 19:23:28 | 显示全部楼层
嗨,弗农,很惊讶我没有收到你在这篇帖子上的回复。,让我们稍微颠簸一下。
我认为这很容易做到,但现在开始胡闹已经太晚了。
如果在那之前没有人帮你解决问题,我明天就试试。
回复

使用道具 举报

48

主题

304

帖子

256

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
240
发表于 2022-7-5 19:24:51 | 显示全部楼层
 
 
非常感谢Dadgad
回复

使用道具 举报

17

主题

1274

帖子

25

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
260
发表于 2022-7-5 19:27:58 | 显示全部楼层
 
尝试:
  1. ;;----------------------=={ Length at Midpoint }==----------------------;;
  2. ;;                                                                      ;;
  3. ;;  This program prompts the user for a selection of objects to be      ;;
  4. ;;  labelled and proceeds to generate an MText object located at        ;;
  5. ;;  the midpoint of each object displaying a Field Expression           ;;
  6. ;;  referencing the length of the object.                               ;;
  7. ;;                                                                      ;;
  8. ;;  The program is compatible for use with Arcs, Circles, Lines,        ;;
  9. ;;  LWPolylines, 2D & 3D Polylines, and under all UCS & View settings.  ;;
  10. ;;                                                                      ;;
  11. ;;  The program will generate MText objects positioned directly over    ;;
  12. ;;  the midpoint of each object, and aligned with the object whilst     ;;
  13. ;;  preserving text readability. The MText will have a background mask  ;;
  14. ;;  enabled and will use the active Text Style and Text Height settings ;;
  15. ;;  at the time of running the program.                                 ;;
  16. ;;----------------------------------------------------------------------;;
  17. ;;  Author:  Lee Mac, Copyright © 2013  -  www.lee-mac.com              ;;
  18. ;;  Above/Below line added by Tom Beauford
  19. ;;----------------------------------------------------------------------;;
  20. ;;  Version 1.1    -    12-11-2013                                      ;;
  21. ;;                                                                      ;;
  22. ;;  First release.                                                      ;;
  23. ;;----------------------------------------------------------------------;;
  24. (defun c:midlen ( / *error* ent fmt idx ins ocs par sel spc txt typ uxa ang pt str1)
  25.    (setq fmt "%lu6") ;; Field Formatting
  26.    (defun *error* ( msg )
  27.        (LM:endundo (LM:acdoc))
  28.        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
  29.            (princ (strcat "\nError: " msg))
  30.        )
  31.        (princ)
  32.    )
  33.    (if
  34.        (setq sel
  35.            (ssget
  36.                (list
  37.                   '(0 . "ARC,CIRCLE,LINE,*POLYLINE")
  38.                   '(-4 . "<NOT")
  39.                       '(-4 . "<AND")
  40.                           '(0 . "POLYLINE")
  41.                           '(-4 . "&")
  42.                           '(70 . 80)
  43.                       '(-4 . "AND>")
  44.                   '(-4 . "NOT>")
  45.                    (if (= 1 (getvar 'cvport))
  46.                        (cons 410 (getvar 'ctab))
  47.                       '(410 . "Model")
  48.                    )
  49.                )
  50.            )
  51.        )
  52.        (progn
  53.            (setq spc
  54.                (vlax-get-property (LM:acdoc)
  55.                    (if (= 1 (getvar 'cvport))
  56.                        'paperspace
  57.                        'modelspace
  58.                    )
  59.                )
  60.            )
  61.            (setq ocs (trans '(0.0 0.0 1.0) 1 0 t)
  62.                  uxa (angle '(0.0 0.0) (trans (getvar 'ucsxdir) 0 ocs t))
  63.            )
  64.    (initget "Yes No")
  65.    (or
  66.      (setq str1 (getkword "\nBelow Line?  [Yes/No] <Yes>: "))
  67.      (setq str1 "Yes")
  68.    )
  69.    (if (= str1 "Yes")
  70.      (setq up-dn (/ pi 2))
  71.      (setq up-dn (-(/ pi 2)))
  72.    )
  73.            (LM:startundo (LM:acdoc))
  74.            (repeat (setq idx (sslength sel))
  75.                (setq ent (ssname sel (setq idx (1- idx)))
  76.                      par (vlax-curve-getparamatdist ent (/ (vlax-curve-getdistatparam ent (vlax-curve-getendparam ent)) 2.0))
  77.                      ins (vlax-curve-getpointatparam ent par)
  78.                      typ (cdr (assoc 0 (entget ent)))
  79.                )
  80.                (setq txt
  81.                    (vlax-invoke spc 'addmtext ins 0.0
  82.                        (strcat
  83.                            "%<\\AcObjProp Object(%<\\_ObjId " (LM:objectid (vlax-ename->vla-object ent)) ">%)."
  84.                            (cond
  85.                                (   (= "CIRCLE" typ) "Circumference")
  86.                                (   (= "ARC"    typ) "ArcLength")
  87.                                (   "Length"   )
  88.                            )
  89.                            " \\f "" fmt "">%"
  90.                        )
  91.                    )
  92.                )
  93.                (setq ins (polar ins(-(LM:readable (- (angle '(0.0 0.0 0.0) (trans (vlax-curve-getfirstderiv ent par) 0 ocs t)) uxa))up-dn)(*(vla-get-Height txt)0.))
  94.                (vla-put-backgroundfill  txt :vlax-true)
  95.                (vla-put-attachmentpoint txt acattachmentpointmiddlecenter)
  96.                (vla-put-insertionpoint  txt (vlax-3D-point ins))
  97.                (vla-put-rotation txt (LM:readable (- (angle '(0.0 0.0 0.0) (trans (vlax-curve-getfirstderiv ent par) 0 ocs t)) uxa)))
  98.         (setq elist (entget (vlax-vla-object->ename txt))
  99.               elist (subst (cons 45 1.15) (assoc 45 elist) elist) ;Set 'Border Offset Factor' to 1.15
  100.               elist (subst (cons 41 (* (cdr (assoc 42 elist))1.015))(assoc 41 elist) elist) ;Trim excess width
  101.         )
  102.         (entmod elist)
  103.            )
  104.            (LM:endundo (LM:acdoc))
  105.        )
  106.    )
  107.    (princ)
  108. )
  109. ;; Readable  -  Lee Mac
  110. ;; Returns an angle corrected for text readability.
  111. (defun LM:readable ( a )
  112.    (   (lambda ( a )
  113.            (if (and (< (* pi 0.5) a) (<= a (* pi 1.5)))
  114.                (LM:readable (+ a pi))
  115.                a
  116.            )
  117.        )
  118.        (rem (+ a pi pi) (+ pi pi))
  119.    )
  120. )
  121. ;; ObjectID  -  Lee Mac
  122. ;; Returns a string containing the ObjectID of a supplied VLA-Object
  123. ;; Compatible with 32-bit & 64-bit systems
  124. (defun LM:objectid ( obj )
  125.    (eval
  126.        (list 'defun 'LM:objectid '( obj )
  127.            (if
  128.                (and
  129.                    (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
  130.                    (vlax-method-applicable-p (vla-get-utility (LM:acdoc)) 'getobjectidstring)
  131.                )
  132.                (list 'vla-getobjectidstring (vla-get-utility (LM:acdoc)) 'obj ':vlax-false)
  133.               '(itoa (vla-get-objectid obj))
  134.            )
  135.        )
  136.    )
  137.    (LM:objectid obj)
  138. )
  139. ;; Start Undo  -  Lee Mac
  140. ;; Opens an Undo Group.
  141. (defun LM:startundo ( doc )
  142.    (LM:endundo doc)
  143.    (vla-startundomark doc)
  144. )
  145. ;; End Undo  -  Lee Mac
  146. ;; Closes an Undo Group.
  147. (defun LM:endundo ( doc )
  148.    (while (= 8 (logand 8 (getvar 'undoctl)))
  149.        (vla-endundomark doc)
  150.    )
  151. )
  152. ;; Active Document  -  Lee Mac
  153. ;; Returns the VLA Active Document Object
  154. (defun LM:acdoc nil
  155.    (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
  156.    (LM:acdoc)
  157. )
  158. (vl-load-com)
  159. (princ
  160.    (strcat
  161.        "\n:: MidLen.lsp | Version 1.0 | \\U+00A9 Lee Mac "
  162.        (menucmd "m=$(edtime,0,yyyy)")
  163.        " www.lee-mac.com ::"
  164.        "\n:: Type "midlen" to Invoke ::"
  165.    )
  166. )
  167. (princ)
  168. ;;----------------------------------------------------------------------;;
  169. ;;                             End of File                              ;;
  170. ;;----------------------------------------------------------------------;;
作为与对象的距离-您可以更改0.8,或将此表达式替换为固定距离。
回复

使用道具 举报

48

主题

304

帖子

256

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
240
发表于 2022-7-5 19:32:22 | 显示全部楼层
 
 
谢谢李。我把0.8换成另一个数字&它成功了。
 
但是你说的“用固定距离替换这个表达式”是什么意思?
 
此外,是否可以使“与线条的距离”与文本的大小成比例?
 
如何更改文本大小?
 
谢谢
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 19:35:41 | 显示全部楼层
只是猜测一下,因为我不太熟练,但我怀疑这将由运行lisp时当前文本样式的文本大小来定义。
值得做一个测试,看看这是否能控制它。
回复

使用道具 举报

48

主题

304

帖子

256

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
240
发表于 2022-7-5 19:38:52 | 显示全部楼层
 
哦它确实奏效了。
回复

使用道具 举报

5

主题

1074

帖子

1088

银币

初来乍到

Rank: 1

铜币
9
发表于 2022-7-5 19:40:13 | 显示全部楼层
嗨,李或任何能帮忙的人。
 
我有几个问题:
 
1) 如何以米而不是毫米列出文本?
我把单位改为米,但还是以毫米为单位
 
2) 如何根据文本大小按比例调整“与线条的距离”?
 
谢谢
回复

使用道具 举报

48

主题

304

帖子

256

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
240
发表于 2022-7-5 19:45:48 | 显示全部楼层
  1. (*(getvar "TEXTSIZE")0.
更改为
  1. (setq fmt "%lu6")

 
我修改了上面的代码,并用
  1. 4

使用textsize对我很有效,因为我没有为文本样式指定高度。这在任何情况下都应该有效,并再次将0.8更改为您需要的任何值,以根据文本的大小按比例调整“与行的距离”。
回复

使用道具 举报

48

主题

304

帖子

256

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
240
发表于 2022-7-5 19:47:24 | 显示全部楼层
回复

使用道具 举报

17

主题

1274

帖子

25

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
260
发表于 2022-7-5 19:51:59 | 显示全部楼层
Change
  1. (setq fmt "%lu6")
to
  1. (setq fmt "%lu6%ct8[0.001]")
 
I modified the code above and replaced
  1. (getvar "textsize")
with
  1. (vla-get-Height txt)
Using the textsize worked for me because I don't assign heights to text styles.  This should work in any case and again change the 0.8 to whatever you need to adjust the "distance from the line" proportionate to the size of the text.
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-12 13:53 , Processed in 0.509444 second(s), 70 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表