zpqcq 发表于 2005-1-3 22:54:00

[求助]块的属性操作

请问怎样修改块的属性值。


例如:块中有一个编号属性,其值为:12345。现将它改为:54321


多谢!

王咣生 发表于 2005-1-3 22:57:00

参考:



<BR>(vl-load-com)


(defun c:mychange ( / ss item blk)<BR>       (if (setq ss (vlex-SelectOnScreen-Filter       (list 0 2)(list "INSERT" "<FONT color=#1111ee><b>actj2tk</b></FONT>")))        ;<FONT color=#f73809><b>换成你的块名<BR></b></FONT>                       (vlax-For item ss<BR>                                       (if (equal (type item) 'vla-object)<BR>        (setq blk (vlax-vla-object-&gt;Ename item))<BR>        (setq blk item)<BR>                                       )<BR>                                       (vlex-ChangeAttributes (list blk <b><FONT color=#0968f7>(cons "R1" ""))) ; R1改成12345, ""改成54321</FONT></b><BR>                                       (terpri)<BR>                       )<BR>       )<BR>)


(defun vlex-SSetExists-p (Name)<BR>       (not<BR>                       (vl-Catch-All-Error-p<BR>                                       (vl-Catch-All-Apply<BR>        'vla-Item<BR>        (list (vla-Get-SelectionSets (vlex-ActiveDocument)) Name)<BR>                                       )<BR>                       )<BR>       )<BR>)


(defun vlex-SelectOnScreen-Filter (GroupCodes FilterLists / ss)<BR>       (if (vlex-SSetExists-p "%TEMP_SET")<BR>                       (vla-Delete<BR>                                       (vla-Item<BR>        (vla-get-SelectionSets (vlex-ActiveDocument))<BR>        "%TEMP_SET"<BR>                                       )<BR>                       )<BR>       )<BR>       (setq ss<BR>                       (vla-Add<BR>                                       (vla-get-SelectionSets (vlex-ActiveDocument))<BR>                                       "%TEMP_SET"<BR>                       )<BR>       )<BR>       (vla-Select ss<BR>                       ACSelectionSetAll nil nil <BR>                       (vlex-IntList-&gt;VarArray GroupCodes)<BR>                       (vlex-VarList-&gt;VarArray FilterLists)<BR>       )<BR>       ss<BR>)


(defun vlex-VarList-&gt;VarArray (aList)<BR>       (vlax-SafeArray-Fill<BR>                       (vlax-Make-SafeArray<BR>                                       vlax-vbVariant         ;(12) Variant<BR>                                       (cons 0 (- (length aList) 1))<BR>                       )<BR>                       aList<BR>       )<BR>)


(defun vlex-IntList-&gt;VarArray (aList)<BR>       (vlax-SafeArray-Fill<BR>                       (vlax-Make-SafeArray<BR>                                       vlax-vbInteger        ; (2) Integer<BR>                                       (cons 0 (- (length aList) 1))<BR>                       )<BR>                       aList<BR>       )<BR>)


(defun vlex-ChangeAttributes (lst / blk item atts)<BR>       (setq blk (vlax-Ename-&gt;vla-Object (car lst))<BR>        lst (cdr lst)<BR>       )<BR>       (if (= (vla-Get-HasAttributes blk) :vlax-true)<BR>                       (progn<BR>                                       (setq atts (vlax-SafeArray-&gt;list<BR>                               (vlax-Variant-Value (vla-GetAttributes blk))<BR>               )<BR>                                       ); setq<BR>                                       (foreach item lst<BR>        (mapcar<BR>               '(lambda (x)<BR><FONT color=#0000ff><B>                                       (if (= (strcase (car item)) (strcase (vla-Get-TagString x)))<BR>                                                       (vla-Put-TextString x (cdr item))<BR>                                       ); endif</B></FONT><BR>               )<BR>               atts<BR>        ); mapcar<BR>                                       ); foreach<BR>                                       (vla-Update blk)<BR>                       )<BR>       ); endif<BR>)


(defun vlex-ActiveDocument ()<BR>       (vla-Get-ActiveDocument (vlax-get-acad-object))<BR>)


如果不明白,请贴上你的dwg图.

zpqcq 发表于 2005-1-4 20:44:00

多谢王斑竹回答我的问题。


王斑竹:我想在R14下实现上述功能,能否用Autolisp啊?


十二分的感谢!

王咣生 发表于 2005-1-4 23:31:00

回复

应该也可以吧,只是相比VLISP要麻烦的多.

meflying 发表于 2005-1-5 08:25:00

autolisp简单多了吧


(defun c:test( / ent ents)<BR>       (setq ent (car (entsel "选择属性块...")))<BR>       (while (/= (cdr (assoc 0 (setq ents (entget (setq ent (entnext ent)))))) "SEQEND")<BR>                       (if (= (cdr (assoc 1 ents)) "12345")<BR>                                       (progn<BR>        (setq ents (subst (cons 1 "54321") (assoc 1 ents) ents))<BR>        (entmod ents)<BR>        (entupd ent)<BR>                                       )<BR>                       )<BR>       )                                       <BR>       (princ)<BR>)

xstlf 发表于 2005-1-5 20:15:00

(setq ent (car (entsel "选择属性块...")))


这句的,ent .为,块的,car.指的是什么?那么,cdr又是对应的是什么呢?


我对块的DXF组码看帮助也看不懂呀,老师讲得详细一点呀。


(while (/= (cdr (assoc 0 (setq ents (entget (setq ent (entnext ent)))))) "SEQEND")<BR>这句,的,seqend,又是指什么呢?


老师们,关于块的DXF,到底怎么构成的呀。为什么CAD里的帮助文件里介绍得这么简单呀。看不懂呀。

meflying 发表于 2005-1-5 20:20:00

你问题这么多,一时也说不清楚,你还是慢慢来吧,不要着急

zpqcq 发表于 2005-1-6 22:40:00

<A name=3587><FONT color=#990000><B>meflying</B></FONT></A>:你好!但好象不能用啊。



我上传了一个R14的DWG文件,其中编号中有7个“12345”需要替换,明细表中有7个“12345”需要替换,图框中有2个“12345”需要替换,我希望选择一次就可以替换这16个“12345”。


请解答,谢谢!

meflying 发表于 2005-1-7 08:28:00

你先说说怎么不能用吧,,,我试了,完全可以用


注意:程序替换的是12345,而不是包含12345的部分

龙龙仔 发表于 2005-1-7 16:46:00

(defun C:TT (/ ENT ENTT N NEWTXT OLDTXT SS STR)
   (setqSS         (ssget "x" '((0 . "INSERT") (66 . 1)))
N         0
OLDTXT "12345"
NEWTXT "54321"
   )
   (repeat (sslength SS)
       (setq ENT (ssname SS N))
       (while (/= (cdr (assoc 0 (entget (setq ENT (entnext ENT)))))
               "SEQEND"
       )
         (if
       (wcmatch (setq STR (cdr (assoc 1 (setq ENTT (entget ENT)))))
         (strcat OLDTXT "*")
   )
   (progn
       (setq STR (strcat NEWTXT (substr STR (1+ (strlen OLDTXT)))))
       ;;(setq STR (vl-string-subst NEWTXT OLDTXT STR))
       (entmod
         (subst (cons 1 STR) (assoc 1 ENTT) ENTT)
       )
       (entupd ENT)
   )
         )
       )
       (setq N (1+ N))
   )
   (princ)
)
页: [1] 2
查看完整版本: [求助]块的属性操作