明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 732|回复: 3

[提问] 关于lisp中改变多行文本文字的宽度比例系数

[复制链接]
发表于 2016-1-29 16:21 | 显示全部楼层 |阅读模式
大家好:
        最近在学习用autolisp编小程序来方便改图画图,说下我的问题吧,我要实现的很简单,就是格式刷的简化功能,我只需要修改文字属性,cad自带的格式刷大面积刷的时候难免会改变图的线条的图层,我要的只是修改文字的情况,一个个找字刷也太费劲了。
        运用像素数据修改,已经实现了对单行文本的这个功能,但是多行文本的像素数据的文字宽度比例居然在1.“”文本内容中,这个我真不知道如何能实现了,求教高手!
发表于 2016-2-1 20:24 | 显示全部楼层
sunduke 发表于 2016-2-1 08:14
我去试试,可能我没有清除多重文字的宽度因子,直接替换失败

初步看了一下正则表达式,一时半会儿也掌握不了。
以最基本的筛选方法做了一个程序,会有一些BUG,比如文字中原来如果含有“\W”等文本会出错,但基本上能满足通常文本的需要。
下面的程序只是对MTEXT的宽度因子根据TEXT的文字宽度进行了设置,其它高度、颜色、图层等请自行设置。

(defun c:TT ()
    (setq ed1 (entget (car (entsel "请选择TEXT实体:"))))
    (setq ed2 (entget (car (entsel "请选择MTEXT实体:"))))
    (setq wid (rtos (cdr (assoc 41 ed1))))
    (setq aa (cdr (assoc 1 ed2)))

    ;;去除宽度因子
    (while (setq StrP (vl-string-search "\\W" aa))
        (setq
            a1 (substr (substr aa (1+ StrP))
                       (+ 2 (vl-string-search ";" (substr aa (1+ StrP))))
                       ) ;_ end of substr
            ) ;_ end of setq
        (setq aa (strcat (substr aa 1 strp) a1))
        ) ;_ end of while
    ;;去除高度因子
    (while (setq StrP (vl-string-search "\\H" aa))
        (setq
            a1 (substr (substr aa (1+ StrP))
                       (+ 2 (vl-string-search ";" (substr aa (1+ StrP))))
                       ) ;_ end of substr
            ) ;_ end of setq
        (setq aa (strcat (substr aa 1 strp) a1))
        ) ;_ end of while
    ;;去除字体定义
    (while (setq StrP (vl-string-search "\\f" aa))
        (setq
            a1 (substr (substr aa (1+ StrP))
                       (+ 2 (vl-string-search ";" (substr aa (1+ StrP))))
                       ) ;_ end of substr
            ) ;_ end of setq
        (setq aa (strcat (substr aa 1 strp) a1))
        ) ;_ end of while
    ;;去除下划线
    (while (setq StrP (vl-string-search "\\L" aa))
        (setq
            a1 (substr (substr aa (1+ StrP))
                       (+ 2 (vl-string-search ";" (substr aa (1+ StrP))))
                       ) ;_ end of substr
            ) ;_ end of setq
        (setq aa (strcat (substr aa 1 strp) a1))
        ) ;_ end of while
    ;;去除上划线
    (while (setq StrP (vl-string-search "\\O" aa))
        (setq
            a1 (substr (substr aa (1+ StrP))
                       (+ 2 (vl-string-search ";" (substr aa (1+ StrP))))
                       ) ;_ end of substr
            ) ;_ end of setq
        (setq aa (strcat (substr aa 1 strp) a1))
        ) ;_ end of while

    ;;去除颜色定义
    (while (setq StrP (vl-string-search "\\C" aa))
        (setq
            a1 (substr (substr aa (1+ StrP))
                       (+ 2 (vl-string-search ";" (substr aa (1+ StrP))))
                       ) ;_ end of substr
            ) ;_ end of setq
        (setq aa (strcat (substr aa 1 strp) a1))
        ) ;_ end of while
    ;;去除字体倾斜因子
    (while (setq StrP (vl-string-search "\\Q" aa))
        (setq
            a1 (substr (substr aa (1+ StrP))
                       (+ 2 (vl-string-search ";" (substr aa (1+ StrP))))
                       ) ;_ end of substr
            ) ;_ end of setq
        (setq aa (strcat (substr aa 1 strp) a1))
        ) ;_ end of while
    ;;去除字间距因子
    (while (setq StrP (vl-string-search "\\T" aa))
        (setq
            a1 (substr (substr aa (1+ StrP))
                       (+ 2 (vl-string-search ";" (substr aa (1+ StrP))))
                       ) ;_ end of substr
            ) ;_ end of setq
        (setq aa (strcat (substr aa 1 strp) a1))
        ) ;_ end of while

    (while (setq StrP (vl-string-search "{" aa))
        (setq aa (strcat (substr aa 1 strp) (substr aa (+ 2 strp))))
        ) ;_ end of while
    (while (setq StrP (vl-string-search "}" aa))
        (setq aa (strcat (substr aa 1 strp) (substr aa (+ 2 strp))))
        ) ;_ end of while
    (setq aa (strcat "{\\W" wid  ";" aa "}"))
    ;;下面只是重新设置了MTEXT整体的宽度因子,其它需要设置
    (entmod (subst (cons 1 aa) (assoc 1 ed2) ed2))
    (princ)
    ) ;_ end of defun

回复 支持 1 反对 0

使用道具 举报

发表于 2016-1-29 19:17 | 显示全部楼层
多重文本允许不同字符有不同的宽度因子,因此使用程序可能无法预知具体的字符并相应调整。
简单的方式是整个多重文本设定一个统一的宽度因子,实现方式为
1)清除多重文字内已有的宽度因子定义(或连带其他所有定义),可在网站搜索使用正则表达式的处理代码实现
2)统一设定宽度因子:将 (strcat "{\\W1.x;" 多重文字内容 "}")重新写入多重文字内容
 楼主| 发表于 2016-2-1 08:14 | 显示全部楼层
kozmosovia 发表于 2016-1-29 19:17
多重文本允许不同字符有不同的宽度因子,因此使用程序可能无法预知具体的字符并相应调整。
简单的方式是整 ...

我去试试,可能我没有清除多重文字的宽度因子,直接替换失败
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-6-16 18:55 , Processed in 0.146067 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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