就主要功能而言,仍然不是我最好的工作,但完成了工作。
- (vl-load-com)
- (defun c:test11 ( / blockSS blockList attName attNumber)
- (if
- (setq blockSS (ssget "X" (list (cons 0 "INSERT") (cons -4 "<xor") (cons 2 "Drawing_Sheet_22x34") (cons 2 "Drawing_Sheet_22x34-H") (cons -4 "xor>"))))
- (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))
- (mapcar '(lambda (x)
- (cb:replaceAttributeValue (strcat "DATE" attNumber) "29-JUN-15" (vlax-ename->vla-object x))
- (cb:replaceAttributeValue (strcat "DESC" attNumber) "BASELINE UPDATE - 101/111 RENOVATIONS" (vlax-ename->vla-object x)))
- blockList)
- ))
- (princ)
-
- )
- (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)
- )
|