有人可以随意清理主功能,我不确定你是否有多个布局,但我已经编写了所有的子功能,所以。。。
- (defun c:test11 ( / )
- (if
- (setq blockSS (ssget "X" (list (cons 0 "INSERT") (cons 2 "Drawing_Sheet_22x34"))))
- (progn
- (setq blockList (mapcar 'cadr (ssnamex blockSS)))
- (setq attName (vla-get-tagstring (car (cb:matchAtts "REV" "REV" (vlax-ename->vla-object(car blockList))))))
- (setq attNumber (substr attName (strlen attName) 1))
- (cb:replaceAttributeValue (strcat "DATE" attNumber) "29-JUN-15" (vlax-ename->vla-object(car blockList)))
- (cb:replaceAttributeValue (strcat "DESC" attNumber) "BASELINE UPDATE - 101/111 RENOVATIONS" (vlax-ename->vla-object(car blockList))))
- )
-
- )
- (defun cb:matchAtts (baseAttName attPrefix Blk / )
- (setq baseAtt (car (vl-remove-if-not '(lambda (x) (= baseAttName (vla-get-tagstring x))) (cb:variantToList (vla-getattributes Blk)))))
- (vl-remove-if-not '(lambda (x)
- (and
- (wcmatch (vla-get-tagstring x) (strcat attPrefix "*"))
- (not (eq (vla-get-tagstring x) baseAttName))
- (eq (vla-get-textstring x) (vla-get-textstring baseAtt))
- ))
- (cb:variantToList (vla-getattributes Blk)))
- )
- (defun cb:variantToList (theVariant / )
- (if (= 'variant (type theVariant))
- (vlax-safearray->list (vlax-variant-value theVariant))
- nil
- )
- )
- ;;;;;Replace Attribute Value;;;;;;;;;
- ;;;;;By: CommandoBill;;;;;;;;;;;;;;;;;
- ;;;;;01/24/15;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;Send a block to this function with an attribute you want to replace with a new value
- ;;;;attName = the name of the attribute which value you want to replace
- ;;;;attNewVal = the new value you want in the attribute
- ;;;;Blk = the vla-object verision of the block which the attribute is in
- (defun cb:replaceAttributeValue (attName attNewVal Blk / )
- (mapcar '(lambda (x) (if (= attName (vla-get-tagstring x))
- (vla-put-textstring x attNewVal))) (cb:variantToList (vla-getattributes Blk)))
- (princ)
- )
|