明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1894|回复: 11

[提问] 求助:单行文字批量转成多行文字时,多行文字的宽度根据单行文字的内容自动调整

[复制链接]
发表于 2015-12-14 13:42 | 显示全部楼层 |阅读模式
本帖最后由 微笑忘记过去 于 2016-7-19 17:49 编辑

在工作中,有时需要对单行文字批量遮罩,由于不想用ET自带的那个【文字遮罩】的功能(因为遮罩不能根据文字的移动而移动),故想通过把单行文字批量转换为多行文字之后,再利用多行文字的背景遮罩来实现,但是通过贱人工具箱将单行文字批量转换为多行文字时,转换后的多行文字背景宽度比文字内容多很多,有没有办法实现单行文字批量转成多行文字时,转换后的多行文字的宽度根据单行文字的内容自动调整为最小遮罩背景呢?想实现的效果如下图所示:

本帖子中包含更多资源

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

x
发表于 2015-12-14 15:36 | 显示全部楼层
本帖最后由 springwillow 于 2015-12-14 16:34 编辑

修改了一版供试用。

本帖子中包含更多资源

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

x

点评

他要的是一个单行文本转成一个多行文本,而不是把所有的单行文本转成一个多行文本  发表于 2020-5-7 14:13

评分

参与人数 3明经币 +3 收起 理由
zhangcan0515 + 1
微笑忘记过去 + 1 很给力!
USER2128 + 1 赞一个!

查看全部评分

发表于 2015-12-15 07:55 | 显示全部楼层
感谢 springwillow 分享学习!!!
 楼主| 发表于 2016-7-19 17:52 | 显示全部楼层
springwillow 发表于 2015-12-14 15:36
修改了一版供试用。

谢谢您的大作,我想实现的效果是转换的多行文字不是自动换行的效果,而是各行之间还是独立的,单行文字转换后文字的位置不变。
 楼主| 发表于 2016-7-19 17:52 | 显示全部楼层
springwillow 发表于 2015-12-14 15:36
修改了一版供试用。

谢谢您的大作,我想实现的效果是转换的多行文字不是自动换行的效果,而是各行之间还是独立的,单行文字转换后文字的位置不变。
发表于 2020-5-7 14:10 | 显示全部楼层
  1. ;;  Text1MtextJust.lsp [command name: T1MJ]
  2. ;http://cadtips.cadalyst.com/multiline-text/convert-text-mtext-without-changing-justification
  3. ;;  TXT2MTXT command does not preserve all aspects of justification.  For
  4. ;;    one selected Text/Attribute-definition entity, retains horizontal component
  5. ;;    [except Aligned/ Fit have Center imposed], but always imposes Top for
  6. ;;    vertical component, regardless of Text entity's original justification.
  7. ;;  T1MJ converts each selected Text or Attribute-Definition entity separately
  8. ;;    to Mtext with same or equivalent justification as original Text, including
  9. ;;    vertical component.
  10. ;;  "Equivalent" for Text/Attribute justifications not used with Mtext:
  11. ;;    Left/Center/Right become Bottom-Left/Bottom-Center/Bottom-Right;
  12. ;;    Middle becomes Middle-Center;
  13. ;;    Aligned/Fit become Bottom-Center with new insertion point half-way
  14. ;;      between original Text entity's baseline alignment/fit points, so that
  15. ;;      any positional change is minimized.
  16. ;;  Will sometimes result in slight positional change, depending on specific
  17. ;;    justification involved, text font, and/or whether text content includes
  18. ;;    characters extending above or below height of capital letters [e.g. lower-
  19. ;;    case letters with descenders, parentheses/brackets/braces, slashes, etc.].
  20. ;;  Fit-justified object will retain original height, but lose width adjustment.
  21. ;;  Kent Cooper, last edited 27 August 2014
  22. ;单行文本转多行文本,并且保留对齐方式

  23. (defun C:T1MJ ; = Text or Attribute Definition to 1-line Mtext, retaining Justification
  24.   (/ *error* cmde doc tss inc tent tobj tins tjust)

  25.   (defun *error* (errmsg)
  26.     (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
  27.       (princ (strcat "\nError: " errmsg))
  28.     ); if
  29.     (vla-endundomark doc)
  30.     (setvar 'cmdecho cmde)
  31.     (princ)
  32.   ); defun - *error*

  33.   (setq
  34.     cmde (getvar 'cmdecho)
  35.     doc (vla-get-activedocument (vlax-get-acad-object))
  36.   ); setq
  37.   (vla-startundomark doc)
  38.   (setvar 'cmdecho 0)
  39.   (prompt "\nTo change Text/Attribute to 1-line Mtext, preserving Justification,")
  40.   (if (setq tss (ssget "_:L" '((0 . "TEXT"))))
  41.     (repeat (setq inc (sslength tss))
  42.       (setq
  43.         tent (ssname tss (setq inc (1- inc)))
  44.         tobj (vlax-ename->vla-object tent)
  45.         tins (vlax-get tobj 'TextAlignmentPoint)
  46.         tjust (vla-get-Alignment tobj)
  47.       ); setq
  48.       (cond
  49.         ((= tjust 0) (setq tjust 7 tins (vlax-get tobj 'InsertionPoint))); Left
  50.         ((< tjust 3) (setq tjust (+ tjust 7))); 1/2 [Center/Right] to 8/9
  51.         ((= tjust 4) (setq tjust 5)); Middle to Middle-Center
  52.         ((member tjust '(3 5)); Aligned/Fit
  53.           (setq
  54.             tjust 8 ; to Bottom-Center
  55.             tins (mapcar '/ (mapcar '+ (vlax-get tobj 'InsertionPoint) tins) '(2 2 2))
  56.               ; with new insertion point
  57.           ); setq
  58.         ); Aligned/Fit
  59.         ((setq tjust (- tjust 5))); all vertical-horizontal pair justifications
  60.       ); cond
  61.       (if (= (vla-get-TextString tobj) "") (vla-put-TextString tobj (vla-get-TagString tobj)))
  62.         ;; if no default content, disappears after TXT2MTXT: impose Tag value for it
  63.         ;; [to use Prompt value instead, change end to (vla-get-PromptString tobj).]
  64.       (command "_.txt2mtxt" tent ""); convert, then
  65.       (setq tobj (vlax-ename->vla-object (entlast))); replace Text as object with new Mtext
  66.       (vla-put-AttachmentPoint tobj tjust); original Text's justification [or equiv.]
  67.       (vlax-put tobj 'InsertionPoint tins); original Text's insertion
  68.     ); repeat
  69.   ); if
  70.   (setvar 'cmdecho cmde)
  71.   (vla-endundomark doc)
  72.   (princ)
  73. ); defun -- T1MJ
  74. (vl-load-com)
  75. (prompt "\nType T1MJ to change Text/Attribute-Definitions to 1-line Mtext, preserving Justification.")



本帖子中包含更多资源

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

x
发表于 2020-5-7 14:12 | 显示全部楼层

点评

网址插件下载不了,能否发一个?1071614492@qq.com  发表于 2023-12-24 12:06
发表于 2020-11-20 20:51 | 显示全部楼层
支持一下,顶起,谢谢各位大佬的分享
发表于 2021-12-20 14:29 | 显示全部楼层

这个好,刚好解决了我,单行转多行的疑问,感谢
发表于 2023-12-22 22:54 | 显示全部楼层
xiaomm250 发表于 2020-5-7 14:12
https://cadtips.cadalyst.com/multiline-text/convert-text-mtext-without-changing-justification?q=mult ...

下载不了,能给个附件?

本帖子中包含更多资源

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

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

本版积分规则

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

GMT+8, 2024-5-17 19:57 , Processed in 0.497745 second(s), 34 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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