添加普通文字到图块成为属性
函数共三个变量:1:图块实体
2:文本实体
3:转换成属性后是否删除文本实体
返回值:新生成的图块名
(Defun vlobj-attach-attrib (blk atx erase / att bbb nxx tmp rtn)
(setqbbb blk
blk (entget bbb)
)
(if (not (assoc 66 blk))
(setq blk (append blk (list (cons 66 1))))
)
(setq nxx (list blk))
(if (and (entnext bbb)
(= (cdr (assoc 0 (entget (entnext bbb)))) "ATTRIB")
)
(while
(/= (cdr (assoc 0 (entget (setq bbb (entnext bbb)))))
"SEQEND"
)
(setq nxx (cons (entget bbb) nxx))
)
)
(if (= (type atx) 'ename)
(setq atx (ssadd atx))
)
(if (and (= (type atx) 'pickset)
(setq bbb -1)
)
(progn
(repeat (sslength atx)
(if (and (setq att (ssname atx (setq bbb (1+ bbb))))
(setq tmp (cdr (assoc 1 (entget att)))
(setq tmp (list
(cons 0 "ATTRIB")
(cons 100 "AcDbEntity")
(cons 100 "AcDbText")
(cons 100 "AcDbAttribute")
(cons 1 tmp)
(cons 2 (substr tmp 1 10)) ;防止TAG太长
(cons 6 "ByBlock")
(cons 7 "STANDARD")
(cons 8 "0")
(list 10 0.0 0.0 0.0)
(list 11 0.0 0.0 0.0)
(cons 40 1.0)
(cons 41 1.0)
(cons 50 0.0)
(cons 51 0.0)
(cons 62 256)
(cons 70 0)
(cons 72 0)
(cons 73 0)
)
)
)
(progn
(foreach bbb '(7 8 10 11 40 41 50 51 72 73)
(setq
tmp (subst (cons bbb (cdr (assoc bbb (entget att))))
(assoc bbb tmp)
tmp
)
)
)
(setq nxx (cons tmp nxx))
)
)
)
(setq nxx(cons (list (cons 0 "SEQEND")
(cons 100 "AcDbEntity")
(cons 8 (cdr (assoc 8 blk)))
)
nxx
)
)
(mapcar 'entmake (reverse nxx))
(setq rtn (entlast))
(if (and erase
(setq bbb -1)
(entdel (cdr (assoc -1 blk)))
)
(repeat(sslength atx)
(entdel (ssname atx (setq bbb (1+ bbb))))
)
)
)
)
rtn
)
Simple VL command
;;;No error check, ugly codes only, not fully tested
(Defun c:addatt(/ blk txt yn)
(if
(and (setq blk (entsel "\n Please pick the block :"))
(setq blk (Car blk))
(= (cdr (assoc 0 (entget blk))) "INSERT")
(null (redraw blk 3))
(princ
"\n Please select text to be attached as attributes :"
)
(setq txt (ssget '((0 . "text"))))
)
(progn
(initget "Yen No")
(if (null (setq yn
(getkword "\n Erase the attached texts :")
)
)
(setq yn "Yes")
)
(vlobj-attach-attrib blk txt (equal yn "Yes"))
)
)
)
参考学习下 谢谢分享 参考学习一下! 顶一个~~` <font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/if.htm" target="_black"><font color="#0000ff">if</font></a>
<font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/and.htm" target="_black"><font color="#0000ff">and</font></a>
<font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/setq.htm" target="_black"><font color="#0000ff">setq</font></a> att <font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/ssname.htm" target="_black"><font color="#0000ff">ssname</font></a> atx <font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/setq.htm" target="_black"><font color="#0000ff">setq</font></a> bbb <font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/1+.htm" target="_black"><font color="#0000ff">1+</font></a> bbb<font color="#ff0000">)</font><font color="#ff0000">)</font><font color="#ff0000">)</font><font color="#ff0000">)</font><br/> <font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/setq.htm" target="_black"><font color="#0000ff">setq</font></a> tmp <font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/cdr.htm" target="_black"><font color="#0000ff">cdr</font></a>
<font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/assoc.htm" target="_black"><font color="#0000ff">assoc</font></a>
<font color="#008000">1</font>
<font color="#ff0000">(</font><a href="http://www.mjtd.com/object/autolisp/entget.htm" target="_black"><font color="#0000ff">entget</font></a> att<font color="#ff0000">)</font><font color="#ff0000">)</font><font color="#ff0000">)</font>;;;;;;;;这个地方少个闭括号 ;;很有趣的結構--是圖塊參考帶屬性,非改變原圖塊為屬性圖塊<br/>;;即相同的圖塊名稱,但有的帶屬性,有的卻沒有屬性<br/> <p>这个问题以前在xdcad讨论过</p><p></p><p>属性是寄生虫。可以在树木种下去的时候有,也可以在种下去以后才有。有了还可以杀虫。</p><p></p> <p>属性不属于块中的一个图元。而是附加上去的一些信息。所以属性的特性都可以单独操作,包括调整字体、对齐方式、修改内容。</p><p>呵呵,而单独添加以前倒一直都没有试过。</p> <p>做这个要用autolisp,好像vlisp做不来的</p><p></p> <p><strong>添加普通文字到图块成为属性</strong></p><strong><p><strong>,有人使用过吗?</strong></p><p><strong>我在CAD2008下无法正常运行,不知什缘故?</strong></p></strong> <p>请问:这个程序一般用在什么情况下?</p><p>我一时间都想不出哪些地方用这个程序比较有用?</p> 好程序,顶起,对我很有用处的
页:
[1]
2