明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 4430|回复: 16

添加普通文字到图块成为属性

  [复制链接]
发表于 2007-2-2 23:34 | 显示全部楼层 |阅读模式
函数共三个变量:
1:图块实体[ENAME]
2:文本实体[ENANE/单个 PICKSET/多个]
3:转换成属性后是否删除文本实体[T/NIL]

返回值:新生成的图块名[ENAME]
  1. (Defun vlobj-attach-attrib (blk atx erase / att bbb nxx tmp rtn)
  2.   (setq  bbb blk
  3.   blk (entget bbb)
  4.   )
  5.   (if (not (assoc 66 blk))
  6.     (setq blk (append blk (list (cons 66 1))))
  7.   )
  8.   (setq nxx (list blk))
  9.   (if (and (entnext bbb)
  10.      (= (cdr (assoc 0 (entget (entnext bbb)))) "ATTRIB")
  11.       )
  12.     (while
  13.       (/= (cdr (assoc 0 (entget (setq bbb (entnext bbb)))))
  14.     "SEQEND"
  15.       )
  16.        (setq nxx (cons (entget bbb) nxx))
  17.     )
  18.   )
  19.   (if (= (type atx) 'ename)
  20.     (setq atx (ssadd atx))
  21.   )
  22.   (if (and (= (type atx) 'pickset)
  23.      (setq bbb -1)
  24.       )
  25.     (progn      
  26.       (repeat (sslength atx)
  27.   (if (and (setq att (ssname atx (setq bbb (1+ bbb))))
  28.      (setq tmp (cdr (assoc 1 (entget att)))  
  29.      (setq tmp (list
  30.            (cons 0 "ATTRIB")
  31.            (cons 100 "AcDbEntity")
  32.            (cons 100 "AcDbText")
  33.            (cons 100 "AcDbAttribute")
  34.            (cons 1 tmp)
  35.            (cons 2 (substr tmp 1 10)) ;防止TAG太长
  36.            (cons 6 "ByBlock")
  37.            (cons 7 "STANDARD")
  38.            (cons 8 "0")
  39.            (list 10 0.0 0.0 0.0)
  40.            (list 11 0.0 0.0 0.0)
  41.            (cons 40 1.0)
  42.            (cons 41 1.0)
  43.            (cons 50 0.0)
  44.            (cons 51 0.0)
  45.            (cons 62 256)
  46.            (cons 70 0)
  47.            (cons 72 0)
  48.            (cons 73 0)
  49.          )
  50.      )
  51.       )
  52.     (progn
  53.       (foreach bbb '(7 8 10 11 40 41 50 51 72 73)
  54.         (setq
  55.     tmp (subst (cons bbb (cdr (assoc bbb (entget att))))
  56.          (assoc bbb tmp)
  57.          tmp
  58.         )
  59.         )
  60.       )
  61.       (setq nxx (cons tmp nxx))
  62.     )
  63.   )
  64.       )
  65.       (setq nxx  (cons (list (cons 0 "SEQEND")
  66.           (cons 100 "AcDbEntity")
  67.           (cons 8 (cdr (assoc 8 blk)))
  68.           )
  69.           nxx
  70.     )
  71.       )
  72.       (mapcar 'entmake (reverse nxx))
  73.       (setq rtn (entlast))
  74.       (if (and erase
  75.          (setq bbb -1)
  76.          (entdel (cdr (assoc -1 blk)))
  77.     )
  78.   (repeat  (sslength atx)
  79.     (entdel (ssname atx (setq bbb (1+ bbb))))
  80.   )
  81.       )
  82.     )
  83.   )
  84.   rtn
  85. )
  86. Simple VL command
  87. ;;;No error check, ugly codes only, not fully tested
  88. (Defun c:addatt  (/ blk txt yn)
  89.   (if
  90.     (and (setq blk (entsel "\n Please pick the block :"))
  91.    (setq blk (Car blk))
  92.    (= (cdr (assoc 0 (entget blk))) "INSERT")
  93.                       (null (redraw blk 3))
  94.    (princ
  95.      "\n Please select text to be attached as attributes :"
  96.    )
  97.    (setq txt (ssget '((0 . "text"))))
  98.     )
  99.      (progn
  100.        (initget "Yen No")
  101.        (if (null (setq yn
  102.       (getkword "\n Erase the attached texts [Yes/No] :")
  103.      )
  104.      )
  105.    (setq yn "Yes")
  106.        )
  107.        (vlobj-attach-attrib blk txt (equal yn "Yes"))
  108.      )
  109.   )
  110. )

评分

参与人数 1明经币 +2 收起 理由
mccad + 2 【好评】好程序

查看全部评分

"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2024-5-21 09:17 | 显示全部楼层
参考学习下 谢谢分享
发表于 2019-6-8 10:13 | 显示全部楼层
参考学习一下!
发表于 2007-2-2 23:45 | 显示全部楼层
顶一个~~`
发表于 2007-2-3 13:48 | 显示全部楼层
(if (and (setq att (ssname atx (setq bbb (1+ bbb))))
    (setq tmp (cdr (assoc 1 (entget att)));;;;;;;;这个地方少个闭括号
发表于 2007-2-5 07:51 | 显示全部楼层
;;很有趣的結構--是圖塊參考帶屬性,非改變原圖塊為屬性圖塊
;;即相同的圖塊名稱,但有的帶屬性,有的卻沒有屬性
发表于 2007-2-5 12:06 | 显示全部楼层

这个问题以前在xdcad讨论过

属性是寄生虫。可以在树木种下去的时候有,也可以在种下去以后才有。有了还可以杀虫。

发表于 2007-2-5 13:53 | 显示全部楼层

属性不属于块中的一个图元。而是附加上去的一些信息。所以属性的特性都可以单独操作,包括调整字体、对齐方式、修改内容。

呵呵,而单独添加以前倒一直都没有试过。

发表于 2007-2-5 15:03 | 显示全部楼层

做这个要用autolisp,好像vlisp做不来的

发表于 2008-12-22 11:48 | 显示全部楼层

添加普通文字到图块成为属性

,有人使用过吗?

我在CAD2008下无法正常运行,不知什缘故?

发表于 2008-12-22 19:42 | 显示全部楼层

请问:这个程序一般用在什么情况下?

我一时间都想不出哪些地方用这个程序比较有用?

发表于 2011-12-27 14:37 | 显示全部楼层
好程序,顶起,对我很有用处的
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-6-16 14:46 , Processed in 0.182569 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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