明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2039|回复: 3

[源码] 求改字高和字宽

[复制链接]
发表于 2013-6-22 00:05 | 显示全部楼层 |阅读模式
10明经币
本帖最后由 无惢 于 2013-8-18 17:26 编辑

原lsp有难度,不求了。
改求改文字属性变为居中,位置不变。有的麻烦发个,好让这悬赏贴沉了。。。


以下内容作废(求lisp,需要公开LIsp程序。
1. 改字体高度为300:要求能对普通文字,CAD标注,天正标注,单一文字的属性块, 单一文字 的块内文字等均能采用复选方式修改;对多文字的属性块和普通块采用单选方式 。且不影响宽度和字体方向,且指定字型为“tssd_china"。
2. 改字宽为0.7:要求能对普通文字,CAD标注,天正标注,单一文字的属性块,单一文字 的块内文字等均能采用复选方式修改;对多文字的属性块和普通块采用单选方式。且不影响字高和字体方向,且指定字型为“tssd_china" 。)




 楼主| 发表于 2013-6-29 08:18 | 显示全部楼层
没人。。。
回复

使用道具 举报

发表于 2013-6-29 21:32 | 显示全部楼层
满足楼主要求有难度,如下程序可供参考。
;;; 修改过的文字编辑器.支持天正字体
(princ "\n修改文字已加载,启动命令GT.")
(defun ef:undobegin ()
  (setvar "CMDECHO" 0)
  (command "_.undo" "_group")
  (princ)
);_结束defun
(defun ef:undoend ()
  (setvar "CMDECHO" 0)
  (command "_.undo" "_end")
  (princ)
);_结束defun
(defun c:xgwz(/ dcl_id1 oba ob1 obn obt ptn otxt txt sty styno lay cyn layno hig wid ang col cnu etlst style layer)
  (vl-load-com)
  (setvar "cmdecho" 0)
  (graphscr)
  (ef:undobegin)
  (setq olderr *error*)
  (defun *error* (msg)
    (princ "\n*ERROR*...")
    (princ msg)
    (princ)
  );_结束defun error.
  (defun set_color (conm / costr)
    (defun map_color (ckey mno)
      (start_image ckey)
      (fill_image 0 0 (dimx_tile ckey) (dimy_tile ckey) mno)
      (end_image)
    );_结束defun_map_color
    (cond
      ((= 0 conm)
(setq costr "Byblock")
      )
      ((= 1 conm)
(setq costr "Red")
      )
      ((= 2 conm)
(setq costr "Yellow")
      )
      ((= 3 conm)
(setq costr "Green")
      )
      ((= 4 conm)
(setq costr "Cyan")
      )
      ((= 5 conm)
(setq costr "Bule")
      )
      ((= 6 conm)
(setq costr "Magenta")
      )
      ((= 7 conm)
(setq costr "color")
      )
      ((= 256 conm)
(setq costr "Bylayer")
      )
      (t
(setq costr "")
      )
    );_结束cond
    (cond
      ((= 0 col)
(map_color "col" 7)
      )
      ((= 256 col)
(map_color "col" (cdr (assoc 62 (tblsearch "layer" lay))))
      )
      (t
(map_color "col" conm)
      )
    );_结束cond
    (if (= 256 conm)
      (set_tile "cnu" (strcat "<" (itoa (cdr (assoc 62 (tblsearch "layer" lay)))) ">" costr))
      (set_tile "cnu" (strcat "<" (itoa conm) ">" costr))
    );_结束if
  );_结束set_color
  (defun map_keylist (key keylst) ; set popuplist
    (start_list key)
    (mapcar
      'add_list
      keylst
    )
    (end_list)
  );_结束map
  (defun layer_get_all (/ lay layer layname)
    (setq layer nil         ; all layer
   lay (tblnext "LAYER" t)
    )
    (while (/= lay nil)
      (setq layname (cdr (assoc 2 lay))
     layer (cons layname layer)
      )
      (setq lay (tblnext "LAYER"))
    )
    (setq layer (acad_strlsort layer))
    layer  ; all layer.
  );_结束defun
  (defun style_get_all (/ sty style sty_list)
    (setq sty_list nil
   sty (tblnext "style" t)
    )
    (setq style (cdr (assoc 2 sty)))
    (while style
      (if (/= "" style)
(setq sty_list (append
    sty_list
    (list style)
         )
)
      );_结束if
      (setq sty (tblnext "style"))
      (setq style (cdr (assoc 2 sty)))
    );_结束while
    (setq sty_list (acad_strlsort sty_list))
    sty_list
  );_结束defun
  (defun set_error (str)
    (set_tile "error" str)
  );_结束defun
  (defun sub_mtext (color entlist / ei newlist)
    (setq ei 0
   newlist nil
    )
    (while (< ei (length entlist))
      (setq newlist (cons (nth ei entlist) newlist))
      (if (= 8 (car (nth ei entlist)))
(setq newlist (cons (cons 62 color) newlist))
      );_结束if
      (setq ei (1+ ei))
    );_结束while
    (reverse newlist)
  );_结束defun
  (setq ob1 (entsel "\n选择要修改的任何文本:"))
  (setq obn (car ob1)
ptn (car (cdr ob1))
  )
  (setq obt (car (nentselp ptn)))
  (setq oba (cdr (assoc 0 (entget obt))))
  (if (or
(= oba "TEXT")
(= oba "MTEXT")
(= oba "ATTRIB")
(= oba "TCH_TEXT")
(= oba "TCH_MTEXT")
      )
    (setq otxt (cdr (assoc 1 (entget obt))))
  );_结束if
  (if (= oba "ATTDEF")
    (setq otxt (cdr (assoc 2 (entget obt))))
  );_结束if
  (if otxt
    (progn
      (setq sty (cdr (assoc 7 (entget obt)))
     lay (cdr (assoc 8 (entget obn)))
     hig (cdr (assoc 40 (entget obt)))
     ang (cdr (assoc 50 (entget obt)))
      );_结束setq
      (if (or
     (= oba "TEXT")
     (= oba "MTEXT")
     (= oba "ATTRIB")
   )
(progn
   (setq col (cdr (assoc 62 (entget obt))))
   (setq wid (cdr (assoc 41 (entget obt))))
)
      )
      (if (= oba "ATTDEF")
(setq col (cdr (assoc 62 (entget obn))))
      );_结束if
      (setq ang (* 180 (/ ang pi)))
      (if (or
     (= oba "TEXT")
     (= oba "MTEXT")
     (= oba "ATTRIB")
     (= oba "ATTDEF")
   )
(progn
   (if (null col)
     (progn
       (setq cyn 0)
       (setq col 256)
     )
     (setq cyn 1)
   );_结束if
);_结束progn
      );_结束if
      (setq style (style_get_all))
      (setq layer (layer_get_all))
      (setq styno (- (length style) (length (member sty style))))
      (setq layno (- (length layer) (length (member lay layer))))
      (if (or
     (= oba "TEXT")
     (= oba "MTEXT")
     (= oba "ATTRIB")
     (= oba "ATTDEF")
   )
(progn
   (setq dclname (cond
     ((setq tempname (vl-filename-mktemp "tt-dcl-tmp.dcl")
     filen (open tempname "w")
      )
       (foreach stream '(
                                            "\n"
                                            "文字修改:dialog {\n"
                                            " label = \"文字编辑器...\";\n"
                                            " : boxed_radio_column {\n"
                                            "  label = \"文字编辑...\";\n"
                                            "  : edit_box {\n"
                                            "   label= \"文字:\";\n"
                                            "   key = \"text\";\n"
                                            "   edit_width = 50;\n"
                                            "  }\n"
                                            "  : row {\n"
                                            "   : popup_list {\n"
                                            "    label=\"样式\";\n"
                                            "    key = \"sty\";\n"
                                            "    edit_width = 13;\n"
                                            "    fixed_width = true;\n"
                                            "   }\n"
                                            "   : edit_box {\n"
                                            "    label=\"高度\";\n"
                                            "    key = \"hig\";\n"
                                            "    edit_width = 7;\n"
                                            "    fixed_width = true;\n"
                                            "   }\n"
                                            "   : edit_box {\n"
                                            "    label=\"宽度\";\n"
                                            "    key = \"wid\";\n"
                                            "    edit_width = 7;\n"
                                            "    fixed_width = true;\n"
                                            "   }\n"
                                            "  }\n"
                                            "  : row {\n"
                                            "   : popup_list {\n"
                                            "    label=\"图层\";\n"
                                            "    key = \"lay\";\n"
                                            "    edit_width = 13;\n"
                                            "    fixed_width = true;\n"
                                            "   }\n"
                                            "   : image_button {\n"
                                            "    key = \"col\";\n"
                                            "    width= 4;\n"
                                            "    aspect_ratio = 0.75;\n"
                                            "    fixed_width = true;\n"
                                            "   }\n"
                                            "   : text_part {\n"
                                            "    key = \"cnu\";\n"
                                            "    width= 12;\n"
                                            "    fixed_width = true;\n"
                                            "   }\n"
                                            "   : edit_box {\n"
                                            "    label=\"角度\";\n"
                                            "    key = \"ang\";\n"
                                            "    edit_width = 7;\n"
                                            "    fixed_width = true;\n"
                                            "   }\n"
                                            "  }\n"
                                            "  spacer_1;\n"
                                            " }\n"
                                            " : row {\n"
                                            "  alignment = right;\n"
                                            "  : spacer {\n"
                                            "   width = 1;\n"
                                            "   fixed_width = true;\n"
                                            "   }\n"
                                            "  ok_cancel;\n"
                                            " }\n"
                                            " errtile;\n"
                                            "}\n"      
       )
         (princ stream filen)
       )
       (close filen)
       tempname
     )
   );_结束cond
   );_结束setq
);_结束progn
(progn
   (setq dclname (cond
     ((setq tempname (vl-filename-mktemp "tt-dcl-tmp.dcl")
     filen (open tempname "w")
      )
       (foreach stream '(
                       "\n"
                                            "文字修改:dialog {\n"
                                            " label = \"文字编辑器...\";\n"
                                            " : boxed_radio_column {\n"
                                            "  label = \"文字编辑...\";\n"
                                            "  : edit_box {\n"
                                            "   label= \"文字:\";\n"
                                            "   key = \"text\";\n"
                                            "   edit_width = 50;\n"
                                            "  }\n"
                                            "  : row {\n"
                                            "   : popup_list {\n"
                                            "    label=\"样式\";\n"
                                            "    key = \"sty\";\n"
                                            "    edit_width = 13;\n"
                                            "    fixed_width = true;\n"
                                            "   }\n"
                                            "   : edit_box {\n"
                                            "    label=\"高度\";\n"
                                            "    key = \"hig\";\n"
                                            "    edit_width = 7;\n"
                                            "    fixed_width = true;\n"
                                            "   }\n"
                                            "  }\n"
                                            "  : row {\n"
                                            "   : popup_list {\n"
                                            "    label=\"图层\";\n"
                                            "    key = \"lay\";\n"
                                            "    edit_width = 13;\n"
                                            "    fixed_width = true;\n"
                                            "   }\n"
                                            "   : edit_box {\n"
                                            "    label=\"角度\";\n"
                                            "    key = \"ang\";\n"
                                            "    edit_width = 7;\n"
                                            "    fixed_width = true;\n"
                                            "   }\n"
                                            "  }\n"
                                            "  spacer_1;\n"
                                            " }\n"
                                            " : row {\n"
                                            "  alignment = right;\n"
                                            "  : spacer {\n"
                                            "   width = 1;\n"
                                            "   fixed_width = true;\n"
                                            "   }\n"
                                            "  ok_cancel;\n"
                                            " }\n"
                                            " errtile;\n"
                                            "}\n"      
       )
         (princ stream filen)
       )
       (close filen)
       tempname
     )
   );_结束cond
   );_结束setq
);_结束progn
      );_结束if
      (setq dcl_id1 (load_dialog dclname))
      (if (not (new_dialog "文字修改" dcl_id1))
(exit)
      );_结束if
      (if (or
     (= oba "TEXT")
     (= oba "MTEXT")
     (= oba "ATTRIB")
     (= oba "ATTDEF")
   )
(progn
   (set_color col)
   (set_tile "wid" (rtos wid 2 3))
   (action_tile "wid" "(setq wid (distof $value))(if (>= 0 wid)(progn (mode_tile \"wid\" 3)(mode_tile \"wid\" 2)(set_error \"Input error ! \"))(set_error \"\"))")
   (action_tile "col" "(if (setq cnu (ACAD_ColorDlg col))(progn (setq col cnu)(set_color col)))")
);_结束prgon
      );_结束if
      (set_tile "text" otxt)
      (set_tile "hig" (rtos hig 2 2))
      (set_tile "ang" (rtos ang 2 2))
      (mode_tile "text" 2)
      (map_keylist "sty" style)
      (set_tile "sty" (itoa styno))
      (map_keylist "lay" layer)
      (set_tile "lay" (itoa layno))
      (action_tile "text" "(setq txt $value)")
      (action_tile "sty" "(setq styno (atoi $value))")
      (action_tile "hig" "(setq hig (distof $value))(if (>= 0 hig)(progn (mode_tile \"hig\" 3)(mode_tile \"hig\" 2)(set_error \"Input error ! \"))(set_error \"\"))")
      (action_tile "lay" "(setq layno (atoi $value))")
      (action_tile "ang" "(setq ang (distof $value))")
      (action_tile "accept" "(done_dialog 1)")
      (action_tile "cancel" "(done_dialog 0)")
      (if (= 1 (start_dialog))
(if txt
   (progn
     (setq sty (nth styno style))
     (setq lay (nth layno layer))
     (setq ang (* (/ ang 180) pi))
     (setq etlst (entget obt))
     (if (= oba "ATTDEF")
       (setq etlst (subst
       (cons 2 txt)
       (assoc 2 etlst)
       etlst
     )
       )
       (setq etlst (subst
       (cons 1 txt)
       (assoc 1 etlst)
       etlst
     )
       )
     );_结束if
     (setq etlst (subst
     (cons 7 sty)
     (assoc 7 etlst)
     etlst
   )
     )
     (setq etlst (subst
     (cons 8 lay)
     (assoc 8 etlst)
     etlst
   )
     )
     (setq etlst (subst
     (cons 40 hig)
     (assoc 40 etlst)
     etlst
   )
     )
     (setq etlst (subst
     (cons 50 ang)
     (assoc 50 etlst)
     etlst
   )
     )
     (if (or
    (= oba "TEXT")
    (= oba "MTEXT")
    (= oba "ATTRIB")
    (= oba "ATTDEF")
  )
       (progn
  (setq etlst (subst
         (cons 41 wid)
         (assoc 41 etlst)
         etlst
       )
  )
  (if (= 1 cyn)
    (setq etlst (subst
    (cons 62 col)
    (assoc 62 etlst)
    etlst
         )
    )
    (if (= "MTEXT" oba)
      (setq etlst (sub_mtext col etlst))
      (setq etlst (cons (cons 62 col) etlst))
    );_结束if
  );_结束if
       );_结束progn
     );_结束if

     (entmod etlst)
     (entupd obt)
     (entupd obn)
   );_结束progn
);_结束if
      );_结束if
      (if (= 11 (start_dialog))
(command "_help")
      );_结束if
    );_结束progn
  );_结束if
  (setq *error* olderr)
  (ef:undoend)
  (unload_dialog dcl_id1)
  (vl-file-delete dclname)
  (setvar "cmdecho" 1)
  (princ)
);_结束defun

回复

使用道具 举报

 楼主| 发表于 2013-6-30 11:27 | 显示全部楼层
这文编功能,执行效率太低,繁冗。。。功能虽然都有,要求也基本达到,但不好参考。
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-8 13:38 , Processed in 0.434219 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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