Script to change block attribute values

Script to change block attribute values

Trenton_Webster9DXH9
Observer Observer
832 Views
3 Replies
Message 1 of 4

Script to change block attribute values

Trenton_Webster9DXH9
Observer
Observer

I have a block that has multiple text attributes that I would like to write a script for to automate changing their values:

Screenshot 2025-02-21 101231.png

What I have so far in a .scr file:

 

;use the attribute edit command and specify one-by-one for attributes and the block name

-ATTEDIT Y 2234CSLN

 

I then hit enter twice so I don't specify any tags or corresponding values and can change any tag or value. I'm not sure how to then select all of the tags for the 2234CSLN block (shown above) and replace their corresponding values.

 

In my mind I would then type:

ROTATION VALUE REPLACE 0 NEXT

XREF#4 VALUE REPLACE NEXT

XREF#3 VALUE REPLACE NEXT

etc...

 

Any help would be greatly appreciated.

 

Thanks!

0 Likes
Accepted solutions (1)
833 Views
3 Replies
Replies (3)
Message 2 of 4

paullimapa
Mentor
Mentor

Or perhaps try the GATTE command:

_.GATTE
; Select block or attribute [Block name]:
_B
; Enter block name: 
2234CSLN
; Select attribute or type attribute name:
Rotation
; Enter new text:
VALUE
; Number of inserts in drawing = #  Process all of them? [Yes/No] <Yes>:
_Y
; then repeat for next attribute
_.GATTE
; Select block or attribute [Block name]:
_B
; Enter block name: 
2234CSLN
; Select attribute or type attribute name:
XREF#4
; Enter new text:
This is Xref #4
; Number of inserts in drawing = #  Process all of them? [Yes/No] <Yes>:
_Y
; then repeat for next attribute

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 4

paullimapa
Mentor
Mentor
Accepted solution

Now if you're running AutoCAD LT, then my previous response on using GATTE won't work because that is an Express Tools command which is not supported in LT.

With ATTEDIT to select the attribute you can use a Crossing window with a set of coordinates that you know the Block is located within.

So this sample script only works if you only have one Block called 2234CSLN and it's located within window of 0,0,0 & 48,36,0.

Furthermore, ATTEDIT does not support Attribute Tag names with # symbol.

So you will need to replace that with an another symbol like Underscore.

So XREF#4 will need to be changed to XREF_4, 

XREF#3 will need to be changed to XREF_3 and etc.

 

This is then the command sequence to try in your script.

 

-ATTEDIT
; Edit attributes one at a time? [Yes/No] <Y>:
_Y
; Enter block name specification <*>:
2234CSLN
; Enter attribute tag specification <*>:
ROTATION
; Enter attribute value specification <*>:

; Select Attributes:
_C
; assumes your block is within this coordinate area
; Specify first corner:
0,0,0
; Specify opposite corner:
48,36,0
; -ATTEDIT Select Attributes:
; Enter an option [Value/Position/Height/Angle/Style/Layer/Color/Next] <N>:
_V
; Enter type of value modification [Change/Replace] <R>:
_R
; Enter new attribute value:
New Value
; Enter an option [Value/Position/Height/Angle/Style/Layer/Color/Next] <N>:

; repeat from the beginning for the next attribute

 

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 4 of 4

Sea-Haven
Mentor
Mentor

Something like this. Similar question is posted elsewhere, normal block and dynamic block.

 

; By AlanH Feb 2025


(defun AH:findatt (obj / ans att atts lst lst2 obj val x)


(setq atts (vlax-invoke obj 'Getattributes))

(setq lst '())
(foreach att atts
  (setq lst (cons (vlax-get att 'Tagstring) lst))
)

(setq lst2 '())
(foreach val lst
  (setq lst2 (cons "" lst2))
  (setq lst2 (cons 20 lst2))
  (setq lst2 (cons 21 lst2))
  (setq lst2 (cons val lst2))
)
(setq lst2 (cons "Please choose " lst2))

(setq ans (AH:getvalsm lst2))
(setq ss (ssget "X" (list (cons 0 "INSERT")(cons 2 bname))))

(repeat (setq K (sslength ss))
(setq blk (vlax-ename->vla-object  (ssname ss (setq k (1- k)))))
(setq attsblk (vlax-invoke blk 'Getattributes))
(setq x 0)
(foreach val ans
  (if (= val "")
   (princ)
   (vlax-put (nth x attsblk) 'textstring (nth x ans))
  )
  (setq x (1+ x))
)
)

(princ)
)

 

Save Multi getvals in a support path, it is auto loaded.

0 Likes