求助:如何用Lisp来更改块名称
<P>求助:如何用Lisp来更改块名称,其余块属性不变。多谢!</P> <P>(command "_.rename" "block" "bbb" "ccc")</P><P>;bbb和ccc分别是块的旧名和新名</P>
请问
请问如何更改无名块的名称 <P>既然是"无名"块,怎么改"名"?</P>我没说清楚
我的意思是对图中已有的匿名块 可否用lisp给它一个固定的名字 <P>Probably we cannot rename the anonymous blocks, but you can create a new block and copy all the objects from the original anonymous block. Then replace the original anonymous block reference.</P> ;;尽管也能为一般图块改名,但本程序主要是为匿名块改名成一般图块。<BR>;; Alin - 25/09/2005<BR>(defun c:RNBLK (/ doc oldBlkObj blks oldBlkDef oldOrigin oldNmae LOOP newName vla-objects sArray ss idc ent)<BR> (setq oldBlkObj (vlax-ename->vla-object<BR> (car (entsel "选择要改名的图块: "))<BR> )<BR> )<BR> (setq blks (vla-get-blocks<BR> (setq doc (vla-get-activedocument (vlax-get-acad-object)))<BR> )<BR> )<BR> (setq oldBlkDef (vla-item blks (vla-get-name oldBlkObj)))<BR> (setq oldOrigin (vla-get-origin oldBlkDef))<BR> (princ "\n原图块名为:")<BR> (princ (setq oldName (vla-get-name oldBlkObj)))<BR> (setq LOOP t)<BR> (while LOOP<BR> (if (not<BR> (tblsearch<BR> "block"<BR> (setq newName (getstring "\n输入新的图块名:"))<BR> )<BR> )<BR> (setq LOOP nil)<BR> (princ "\n该图块名在本图中已定义过,请另选。")<BR> )<BR> )<BR> (setq newBlkDef (vla-add blks oldOrigin newName))<BR> (setq vla-objects '())<BR> (vlax-for obj oldBlkDef<BR> (setq vla-objects (cons obj vla-objects))<BR> )<BR> (setq sArray (vlax-safearray-fill<BR> (vlax-make-safearray<BR> vlax-vbobject<BR> (cons 0 (1- (length vla-objects)))<BR> )<BR> vla-objects<BR> )<BR> )<BR> (vla-copyobjects doc sArray newBlkDef nil)<BR> (setq ss (ssget "x" (list (cons 0 "INSERT") (cons 2 (strcat "`" oldName)))))<BR> (setq idx 0)<BR> (while (< idx (sslength ss))<BR> (setq ent (entget (ssname ss idx)))<BR> (setq ent (subst (cons 2 newName) (assoc 2 ent) ent))<BR> (setq ent (subst (cons 70 0) (assoc 70 ent) ent))<BR> (entmod ent)<BR> (setq idx (1+ idx))<BR> )<BR> (princ)<BR>) 很好的程序支持下!
页:
[1]