Jump to content

I need help, I want to change the attribute value of all the blocks in the drawing, but one chosen


Recommended Posts

Posted

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

Posted

bloks have different names
but they all have the same attribute number and attribute names

Posted (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 by Emmanuel Delay

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...