查找/替换属性块
你好我开始写一些代码,但我的时间不多了,我需要在本周完成。我想做的是用一个窗口创建一个带有块的选择集。搜索这些块内的属性值,如果它与旧值匹配,则替换为新值。(defun C:TEST()(setq STOLPNR\u OLD“06169”)(setq STOLPNR\u NEW“TEST050”)(setq ss1(ssget))(setq Att1“#STOLPNR”);attribute tag i stolpe(foreach att(vlax invoke(vlax ename->vla object(ssname SS1 0))'getattributes)(if(=Att1(strcase(vla get tagstring att))(if(=STOLPNR\u OLD(strcase(vla get textstring att)))(vla put textstring att STOLPNR\u NEW));如果结束);如果结束);结束foreach);结束defun 欢迎来到cadTutor。
您希望用另一个值替换的旧值是什么?当然,新的价值是什么? 我在第一篇文章中没有阅读你的代码,所以我想这应该是直截了当的。
试试看,让我知道。。。
(defun c:Test (/ ss)
;; Tharwat 27.11.2013 ;;
(if (setq ss (ssget "_:L" '((0 . "INSERT") (66 . 1))))
((lambda (u / sn e)
(while (setq sn (ssname ss (setq u (1+ u))))
(while (and (setq sn (entnext sn)) (/= (cdr (assoc 0 (setq e (entget sn)))) "SEQEND"))
(if (and (eq (cdr (assoc 1 e)) "06169") (eq (strcase (cdr (assoc 2 e))) "#STOLPNR"))
(entmod (subst (cons 1 "TEST050") (assoc 1 e) e))
)
)
)
)
-1
)
)
(princ)
)
请阅读代码发布指南并编辑您的帖子,将您的代码包含在代码标签中。 这是一个工作VL版本更改2块
; changes to issued for construction
: thanks to lee mac for original code
(vl-load-com)
; 1.Get current date in mm/dd/yy format.
(defun ddmmyy (/ x today)
(setvar "cmdecho" 0)
(setq x (getvar "CDATE")) ; get current date
(setq today ( rtos x 2 4)) ; convert to a string
(setq date (strcat (substr today 7 2) "." (substr today 5 2) "." (substr today 3 2) ))
)
(setq oldtag1 "DRAWING_STATUS") ;attribute tag name
(setq newstr1 "ISSUED FOR CONSTRUCTION")
(setq oldtag2 "REV_NO");attribute tag name
(setq newstr2 "0")
(setq ss1 (ssget "x"'((0 . "INSERT") (2 . "DA1DRTXT"))))
(setq inc (sslength ss1))
(repeat inc
(foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS1 (setq inc (1- inc)) )) 'getattributes)
(if (= oldtag1 (strcase (vla-get-tagstring att)))
(vla-put-textstring att newstr1)
) ; end if
(if (= oldtag2 (strcase (vla-get-tagstring att)))
(vla-put-textstring att newstr2)
) ; end if
) ; end for
) ;end repeat
(setq oldtag1 "REV-NO")
(setq newstr1 "0")
(ddmmyy)
(setq oldtag2 "DATE")
(setq newstr2 date)
(setq oldtag3 "AMENDMENT")
(setq newstr3 "ISSUED FOR CONSTRUCTION")
(setq ss2 (ssget "x"'((0 . "INSERT") (2 . "REVTABLE"))))
(setq inc (sslength ss2))
(repeat inc
(foreach att (vlax-invoke (vlax-ename->vla-object (ssname ss2 (setq inc (1- inc)))) 'getattributes)
(if (= oldtag1 (strcase (vla-get-tagstring att)))
(vla-put-textstring att newstr1)
)
(if (= oldtag2 (strcase (vla-get-tagstring att)))
(vla-put-textstring att newstr2)
)
(if (= oldtag3 (strcase (vla-get-tagstring att)))
(vla-put-textstring att newstr3)
)
)
)
(setq ss1 nil)
; (setq ss2 nil)
(princ)
页:
[1]