plecs Posted November 29, 2021 Posted November 29, 2021 My bloks have 15 attributes and I want to change the value to one attribute, ex. size or length or step can someone help me Quote
tombu Posted November 29, 2021 Posted November 29, 2021 Not enough information. Do all the blocks have the same name? Do all the attributes have the same tag name? Are those same same tag names used in other blocks? Check out Lee Mac's Attribute Functions lisp: http://lee-mac.com/attributefunctions.html Quote
plecs Posted November 30, 2021 Author Posted November 30, 2021 bloks have different names but they all have the same attribute number and attribute names Quote
Emmanuel Delay Posted December 1, 2021 Posted December 1, 2021 (edited) Ah, I get it. Is this it? Command CAVAB. (vl-load-com) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; http://www.lee-mac.com/attributefunctions.html ;; Get Attribute Value - Lee Mac ;; Returns the value held by the specified tag within the supplied block, if present. ;; blk - [vla] VLA Block Reference Object ;; tag - [str] Attribute TagString ;; Returns: [str] Attribute value, else nil if tag is not found. (defun LM:vl-getattributevalue ( blk tag ) (setq tag (strcase tag)) (vl-some '(lambda ( att ) (if (= tag (strcase (vla-get-tagstring att))) (vla-get-textstring att))) (vlax-invoke blk 'getattributes)) ) ;; Get Attribute Values - Lee Mac ;; Returns an association list of attributes present in the supplied block. ;; blk - [vla] VLA Block Reference Object ;; Returns: [lst] Association list of ((<tag> . <value>) ... ) (defun LM:vl-getattributevalues ( blk ) (mapcar '(lambda ( att ) (cons (vla-get-tagstring att) (vla-get-textstring att))) (vlax-invoke blk 'getattributes)) ) ;; Set Attribute Value - Lee Mac ;; Sets the value of the first attribute with the given tag found within the block, if present. ;; blk - [vla] VLA Block Reference Object ;; tag - [str] Attribute TagString ;; val - [str] Attribute Value ;; Returns: [str] Attribute value if successful, else nil. (defun LM:vl-setattributevalue ( blk tag val ) (setq tag (strcase tag)) (vl-some '(lambda ( att ) (if (= tag (strcase (vla-get-tagstring att))) (progn (vla-put-textstring att val) val) ) ) (vlax-invoke blk 'getattributes) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; CAVAB, for: Change the Attribute Value of All the Blocks (defun c:cavab ( / tag ss i blk val atts) (setq tag (getstring "\nGive attribute name or press enter, then select an attribute from an existing block: ")) (if (= "" tag) (setq tag (cdr (assoc 2 (entget (car (nentsel "Select attribute: ")))))) ) (setq val (getstring "\nNew value: " T)) ;; In case you don't really want to select all the blocks in the entire DWG, then remove "_X". Then you'll be asked to select the blocks manually. (setq ss (ssget "_X" '((0 . "*INSERT") (66 . 1)))) (setq i 0) (repeat (sslength ss) (setq blk (ssname ss i)) (setq atts (LM:vl-getattributevalues (vlax-ename->vla-object blk))) ;; check if the tag exists in this block. (if (assoc tag atts) (LM:vl-setattributevalue (vlax-ename->vla-object blk) tag val) ) (setq i (+ i 1)) ) (princ) ) Edited December 1, 2021 by Emmanuel Delay Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.