明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1836|回复: 9

[已解答] 批量修改文字高度及型式

[复制链接]
发表于 2016-7-5 09:30 | 显示全部楼层 |阅读模式
  1. (defun c:fixtext ( / ss1 index newht newstyle styledata defwidth ename txtobj)
  2. (setq ss1 (ssget (list (cons 0 "*text")))
  3.       index 0
  4.       newht (getstring "\n输入文字高度: ")
  5.       newstyle (getstring "\输入文字型式: ")
  6. )
  7. (if (setq styledata (tblsearch "style" newstyle))
  8.     (progn
  9.        (setq defwidth (cdr (assoc 41 styledata)))
  10.        (while (setq ename (ssname ss1 index))
  11.               (setq txtobj (vlax-ename->vla-object ename))
  12.               (vlax-put-property txtobj 'Height newht)
  13.               (vlax-put-property txtobj 'StyleName newstyle)
  14.               (if (vlax-property-available-p txtobj 'ScaleFactor)
  15.                   (vlax-put-property txtobj 'ScaleFactor defwidth)
  16.               )
  17.               (setq index (1+ index))
  18.        )
  19.     )
  20.     (princ "\n输入文字型式不存在!")
  21. )
  22. (princ)
  23. )
如何在输入文字高度及输入文字型式这二行增加,如果输入为空白(直接按ENTER),自定输入为某值?

"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2016-7-5 12:45 | 显示全部楼层
本帖最后由 chg 于 2016-7-5 12:47 编辑

(initget 128)
(setq newht (getstring "\n输入文字高度: <3>"))
;;;如果直接回车,就默认高度是3,这里也可以用一个全局变量记住上次输入的数值
;;判断是否是直接回车
(if (null newht)
   (progn
    (setq newht 3)......
    )))
;;下面的方法和这个一样
 楼主| 发表于 2016-7-5 13:20 | 显示全部楼层
chg 发表于 2016-7-5 12:45
(initget 128)
(setq newht (getstring "\n输入文字高度: "))
;;;如果直接回车,就默认高度是3,这里也可 ...
  1. (defun c:fixtext ( / ss1 index newht newstyle styledata defwidth ename txtobj)
  2. (setq ss1 (ssget (list (cons 0 "*text")))
  3.       index 0
  4.       (initget 128)
  5.       (setq newht (getstring "\输入文字高度: <375>"))
  6.        (if (null newht)
  7.         (progn
  8.          (setq newht 375)
  9.         )
  10.        )
  11.       (setq newstyle (getstring "\n输入文字型式: <aa-txt>"))
  12.        (if (null newstyle)
  13.         (progn
  14.          (setq newstyle aa-txt)
  15.         )
  16.        )
  17.       
  18. )
  19. (if (setq styledata (tblsearch "style" newstyle))
  20.     (progn
  21.        (setq defwidth (cdr (assoc 41 styledata)))
  22.        (while (setq ename (ssname ss1 index))
  23.               (setq txtobj (vlax-ename->vla-object ename))
  24.               (vlax-put-property txtobj 'Height newht)
  25.               (vlax-put-property txtobj 'StyleName newstyle)
  26.               (if (vlax-property-available-p txtobj 'ScaleFactor)
  27.                   (vlax-put-property txtobj 'ScaleFactor defwidth)
  28.               )
  29.               (setq index (1+ index))
  30.        )
  31.     )
  32.     (princ "\n文字型式不存在")
  33. )
  34. (princ)
  35. )
依你上面的说明进行修改,但是显示文法错误,是那里错了?

发表于 2016-7-5 16:12 | 显示全部楼层
baoxiaozhong 发表于 2016-7-5 13:20
依你上面的说明进行修改,但是显示文法错误,是那里错了?

输入文字高度使用getdist,不是使用getstring。
 楼主| 发表于 2016-7-5 16:46 | 显示全部楼层
ll_j 发表于 2016-7-5 16:12
输入文字高度使用getdist,不是使用getstring。

修正为 getdist ,还是会出现文法错误,如果没有新设判断语法,getstring是可以正常执行的。
发表于 2016-7-5 17:01 | 显示全部楼层
baoxiaozhong 发表于 2016-7-5 16:46
修正为 getdist ,还是会出现文法错误,如果没有新设判断语法,getstring是可以正常执行的。

第一个setq的闭括号位置错了。
格式化后已经可以看出,initget开始的输入部分已经变成setq的内容了。
 楼主| 发表于 2016-7-5 17:26 | 显示全部楼层
本帖最后由 baoxiaozhong 于 2016-7-5 17:30 编辑
ll_j 發表於 2016-7-5 17:01
第一個setq的閉括號位置錯了。
格式化後已經可以看出,initget開始的輸入部分已經變成setq的內容了。

我用過 ULTRAEDIT 的LISP 格式確認過了,第一個 setq ss1 左括號,確認是對應到輸入文字型式的右括號後面,也就是第六個setq之前的if 左括號前,我上面編碼排版,就是我用 ULTRAEDIT 調整過的。

本帖子中包含更多资源

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

x
发表于 2016-7-5 19:36 | 显示全部楼层
baoxiaozhong 发表于 2016-7-5 17:26
我用過 ULTRAEDIT 的LISP 格式確認過了,第一個 setq ss1 左括號,確認是對應到輸入文字型式的右括號後面 ...

这一段:
  1. (defun c:fixtext ( / ss1 index newht newstyle styledata defwidth ename txtobj)
  2. (setq ss1 (ssget (list (cons 0 "*text")))      index 0
  3. )                                                         ;比括号应该在这里
  4.       (initget 128)
  5.       (setq newht (getstring "\输入文字高度: <375>"))
  6.        (if (null newht)
  7.         (progn         (setq newht 375)        )
  8.        )
  9.       (setq newstyle (getstring "\n输入文字型式: <aa-txt>"))
  10. ...
 楼主| 发表于 2016-7-5 20:59 | 显示全部楼层
ll_j 发表于 2016-7-5 19:36
这一段:

已解決了,謝謝。
发表于 2019-1-23 16:31 | 显示全部楼层
很强大,谢谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-28 14:41 , Processed in 0.330542 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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