明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3535|回复: 5

[基础] 求---多个单行文字水平对齐 LISP

[复制链接]
发表于 2009-12-22 13:38:00 | 显示全部楼层 |阅读模式
有没有。用LISP.把多个单行文字进行按点或线进行水平对齐的。。编辑文字经常遇到。请各位帮一帮。谢啦。。
发表于 2009-12-22 23:43:00 | 显示全部楼层
用Vlisp写了一个
  1. ;;;;文本水平对齐
  2. ;;;by:lihuili 2009-12-22
  3. (vl-load-com)
  4. (defun c:txt_hor_Alignment (/ Ent Obj InsPt ss TxtList item text_InsPt NewInsPt)
  5.   (setq Ent (entsel "\n 选择要对齐的参考文本(位置不变的文本): "))
  6.   (if (and
  7. Ent
  8. (= (value 0 (entget (car Ent))) "TEXT")
  9. (not (redraw (car Ent) 3))
  10.       )
  11.     (progn
  12.       (setq Obj (MakeX (car Ent)))
  13.       (if (= (vla-get-Alignment Obj) 0)
  14. (setq InsPt (safearray-value
  15.         (variant-value (vla-get-InsertionPoint Obj))
  16.       )
  17. )
  18. (setq
  19.    InsPt (safearray-value
  20.     (variant-value (vla-get-TextAlignmentPoint Obj))
  21.   )
  22. )
  23.       )
  24.       (prompt "\n选择其他与参考对齐的文本(要改变位置)!")
  25.       (if (setq ss (ssget '((0 . "TEXT"))))
  26. (progn
  27.    (setq TxtList (ss->Objlist ss))
  28.    (foreach item TxtList
  29.      (if (= (vla-get-Alignment item) 0)
  30.        (setq text_InsPt
  31.        (safearray-value
  32.          (variant-value (vla-get-InsertionPoint item))
  33.        )
  34.        )
  35.        (setq text_InsPt
  36.        (safearray-value
  37.          (variant-value
  38.     (vla-get-TextAlignmentPoint item)
  39.          )
  40.        )
  41.        )
  42.      )
  43.      (setq
  44.        InsPt (list (car text_InsPt)
  45.      (cadr InsPt)
  46.      (caddr InsPt)
  47.       )
  48.      )
  49.      (setq NewInsPt (vlax-3d-point InsPt))
  50.      (if (= (vla-get-Alignment item) 0)
  51.        (vla-put-InsertionPoint item NewInsPt)
  52.        (vla-put-TextAlignmentPoint item NewInsPt)
  53.      )
  54.      (redraw (car Ent) 4)
  55.    )
  56. )
  57.       )
  58.     )
  59.   )
  60.   (princ)
  61. )
  62. (defun VALUE (num ent /)
  63. (cdr (assoc num ent))
  64. )
  65. (defun MakeX (entname)
  66. (vlax-ename->vla-object entname)
  67. )
  68. (defun ss->Objlist (ss / RtnList temp1)
  69.   (while (setq temp1 (ssname ss 0))
  70.     (setq RtnList (cons (vlax-ename->vla-object temp1) RtnList))
  71.     (ssdel temp1 ss)
  72.   )
  73.   RtnList
  74. )
  75.   
发表于 2009-12-30 22:22:00 | 显示全部楼层
我以前写过一个,可以X和Y向都可以选择用的,你看一下吧。
  1. (defun c:tta(/ txtsel TXTSEL_Num basept basetxt xcoor_basept ycoor_basept txtmb
  2.       dokey i txti txtnew txti_pt xcoor_txti ycoor_txti txti_pt_new )
  3.    (princ "\n文本自动对齐!Design by Ahill!Copyright@2007\n")
  4.    (setvar "cmdecho" 0)
  5.    (princ "\n请选择欲对齐的文本实体(自动滤去非文字实体):")
  6.    (while (if
  7.     (SETQ txtsel (SSGET '((-4 . "<OR" )(0 . "TEXT") (0 . "MTEXT")(-4 . "OR>"))))
  8.      T
  9.      nil)
  10. (SETQ TXTSEL_Num (sslength txtsel))
  11.     (if     (not (setq basept (getpoint "\n点取对齐点<选取参照文字实体>: ")))
  12.   (progn
  13.      (princ "\n选取参照文字实体:")
  14.      (SETQ basetxt (SSGET '((-4 . "<OR" )(0 . "TEXT") (0 . "MTEXT")(-4 . "OR>"))))
  15.      (if (= (cdr (assoc 0 (entget (ssname basetxt 0)))) "MTEXT")
  16.       (progn
  17.        (setq basept (cdr (assoc 10 (entget (ssname basetxt 0)))))
  18.       )
  19.    
  20.      (progn
  21.     (setq mb72 (cdr (assoc 72 (entget (ssname basetxt 0)))))
  22.     (setq mb73 (cdr (assoc 73 (entget (ssname basetxt 0)))))
  23.            (if (or (/= 0 mb72) (/= 0 mb73))
  24.      (setq basept (cdr (assoc 11 (entget (ssname basetxt 0)))))
  25.     )
  26.     (if (and (= 0 mb72) (= 0 mb73))  
  27.        (setq basept (cdr (assoc 10 (entget (ssname basetxt 0))))) ;获取基准文字座标
  28.       )
  29.      )
  30.      )
  31.   )
  32. )
  33.    (setq xcoor_basept (car basept))
  34.    (setq ycoor_basept (cadr basept))
  35. (if (not (setq dokey (getint "\n输入对齐方向 <1>沿X方向对齐 / <2>沿Y方向对齐 <2>:")))
  36.     (setq dokey 2)
  37.   )
  38.    (setq i 0)
  39.    (repeat TXTSEL_Num  
  40.    
  41.   (setq txti (entget (ssname txtsel i)))  
  42.    
  43.     (setq mb72 (cdr (assoc 72  txti )))
  44.   (setq mb73 (cdr (assoc 73  txti )))
  45.    
  46.   (if (and (or (/= 0 mb72) (/= 0 mb73)) (/= (cdr (assoc 0 txti)) "MTEXT"))
  47.      (progn
  48.       (setq txti_pt (cdr (assoc 11  txti )))
  49.       (setq txtmb 11)
  50.    )
  51.   )
  52.   (if (or (and (= 0 mb72) (= 0 mb73)) (= (cdr (assoc 0 txti)) "MTEXT"))
  53.      (progn
  54.       (setq txti_pt (cdr (assoc 10 txti )))
  55.       (setq txtmb 10)
  56.      )
  57.   )
  58.    
  59.    
  60.     (setq xcoor_txti (car txti_pt))
  61.     (setq ycoor_txti (cadr txti_pt))
  62.     (if (= dokey 2)
  63.      (progn
  64.       (setq txti_pt_new (list xcoor_txti ycoor_basept (caddr txti_pt)))
  65.      )
  66.   )
  67.     (if (= dokey 1)
  68.      (progn
  69.       (setq txti_pt_new (list xcoor_basept ycoor_txti  (caddr txti_pt)))
  70.      )
  71.   )
  72.     (setq txti_pt_new (cons txtmb (list (car txti_pt_new) (cadr txti_pt_new) (caddr txti_pt_new))))
  73.     (setq txti_pt (cons txtmb (list (car txti_pt) (cadr txti_pt) (caddr txti_pt))))
  74.     (setq txtnew (subst txti_pt_new txti_pt txti))
  75.     (entmod txtnew)
  76.     (setq i (+ 1 i))
  77. )
  78.      (princ "\n请选择欲对齐的文本实体(自动滤去非文字实体):")
  79.      )
  80.   (setvar "cmdecho" 1)
  81.   (princ)
  82. )
  83. (princ "\n TTA:文本对齐!Design by Ahill!Copyright@2007")
 楼主| 发表于 2010-1-25 21:00:00 | 显示全部楼层

谢谢,两位兄台了。

发表于 2010-12-9 14:52:46 | 显示全部楼层
谢谢2位前辈的分享!
发表于 2010-12-9 15:34:33 | 显示全部楼层
非常好,感谢分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-10-2 16:16 , Processed in 0.188171 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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