Hey Lemons, -attedit has it's limitations, it can't grab an attribute that doesn't currently have a value assigned.
Here's a method I sometimes use, it first parses the block list looking for an attribute tag, adding the block name to a list.
This might be overkill in some cases, it was developed for a situation where we might have several block names that include a unique tag identifier and the block list was still being developed. It was also linked up with information that was extracted from a database and meant to potentially transfer information to several hundred blocks with several attributes.
So the first portion can be eliminated and anyone can opt to use the portion starting at (setq block_list (ssget "x" '((0 . "insert") (2 . "block_name")))), removing the ";" preceding it, of course.
Code:
(vl-load-com)
(setq blockname_variable "ATT_VAL")
(setq found_list nil)
(setq blk_table (tblnext "BLOCK" 1))
(while (/= blk_table nil) ;while1
(setq items nil)
(vlax-for item
(vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) (cdr (assoc 2 blk_table)))
(setq items (cons (vlax-vla-object->ename item) items))
)
(setq index 0)
(repeat (length items)
(setq ename (nth index items))
(setq blkrefobj (vlax-ename->vla-object ename))
(if (and (= (cdr (assoc 0 (entget ename))) "ATTDEF") (= (vla-get-TagString blkrefobj) blockname_variable))
(setq found_list (append found_list (list (cdr (assoc 2 blk_table)))))
)
(setq index (+ index 1))
)
(setq blk_table (tblnext "BLOCK"))
)
(setq foundlist_string nil)
(setq foundlist_index 0)
(if found_list
(progn
(repeat (length found_list)
(if foundlist_string
(setq foundlist_string (strcat foundlist_string "," (nth foundlist_index found_list)))
(setq foundlist_string (nth foundlist_index found_list))
)
(setq foundlist_index (+ foundlist_index 1))
)
(setq found_list (list (cons 0 "insert") (cons 2 foundlist_string)))
)
)
(setq block_list (ssget "x" found_list))
;if you know the block name you can use, you don't need to search through the block table.
;this is good in the oft chance you have a wide variety of block names that use the attribute tag
;(setq block_list (ssget "x" '((0 . "insert") (2 . "block_name")))) ; multiple -> (2 . "block1,block2,blokc3")
(if block_list
(repeat (setq block_index (sslength block_list))
(setq obj_name (vlax-ename->vla-object (ssname block_list (setq block_index (- block_index 1)))))
(setq process nil)
(foreach att (append (vlax-invoke obj_name 'GetAttributes) (vlax-invoke obj_name 'GetConstantAttributes))
(cond ((= (vla-get-TagString att) "ATT_VAL") (vla-put-TextString att "NEW TEXT VALUE"))
;search for primary attribute within block and update additional attributes such as SHT_NAME ... SHT_NUM, ISSUE_DATE, etc
((= (vla-get-TagString att) "ADD1_VAL") (vla-put-TextString att "ADDITIONAL ATTRIBUTE ASSOCIATED WITH ATT_VAL"))
((= (vla-get-TagString att) "ADD2_VAL") (vla-put-TextString att "ADDITIONAL ATTRIBUTE ASSOCIATED WITH ATT_VAL"))
((= (vla-get-TagString att) "ADD3_VAL") (vla-put-TextString att "ADDITIONAL ATTRIBUTE ASSOCIATED WITH ATT_VAL"))
)
)
)
)
I apologize for the drawn out code names, I usually try to be a little more descriptive in my code because simple variable names don't usually mean much to me, especially 6 months down the line after I used "e" or "h" for several different programs. LOL!