Author Topic: Change the value of multiple attributes  (Read 180 times)

0 Members and 1 Guest are viewing this topic.


  • Newt
  • Posts: 39
Change the value of multiple attributes
« on: October 14, 2020, 09:08:04 AM »
Hello to the forum,

I have a 5-level plan on which there is a block in each room with a "N°" attribute that numbers the fire detectors.
I have to place its blocks on each level in the same place with hotel numbering, 100 for level 1, 200 for level 2, etc.
Is it possible with a lisp to modify the value of the attribute so as not to enter them again by hand which is tedious.

I would like to copy my blocks from level 1 and paste them to level 2 and transform my blocks with value 100, 101, 102, etc. with a value of 200, 201, 202, etc.

Thank you in advance
Best regards


  • Swamp Rat
  • Posts: 537
  • 30 + years of using Autocad
Re: Change the value of multiple attributes
« Reply #1 on: October 14, 2020, 08:23:46 PM »
Maybe a simple solution is copy the blocks to one side, then use a block att renumber of adding 100 to every block then copy back, so if you had 5 levels copy 4 times say 200 400 600 800 to right then copy back the same distance.

There is plenty of update 1 attribute code examples out there, have a google.

A man who never made a mistake never made anything


  • Newt
  • Posts: 39
Re: Change the value of multiple attributes
« Reply #2 on: October 16, 2020, 02:54:21 PM »

I allow myself to post an answer obtained on another forum (CadXp) in order to share.
The ATT_ADD lisp, below, does exactly what wanted to do.

But unfortunately I had a problem with a block that had a solid hatch in the background and the lisp was not working properly.

We must therefore do the little trick below before launching the ATT_ADD lisp.

RG (Regen)
Thus ALL Hatching and Flat colors "disappear"

Execution of the ATT_ADD routine ...

RG (Regen)
Thus ALL Hatching and Solid colors "come back"

Code: [Select]
;; Commande:  ATT_ADD
;; par Gilles Chanteau (Anciennement ADDATT) -
;; Pour ajouter/soustraire une valeur numerique SIMPLE
;; a un Attribut SIMPLE sur un Bloc SIMPLE
;; Modifiée le 15/10/2020 - Luna
;; -> Ajout de la prise en compte de blocs dynamiques et modification de l'application des fonctions
;; -> Utilisation des fonctions (setpropertyvalue) et (getpropertyvalue) apparues depuis 2014 (?)

(defun c:ATT_ADD (/ Get-att-list att lst tag blc name add ss n val txt)

        (defun Get-att-list (ename / Att Att_List)

                (setq Att_List (mapcar '(lambda (att) (cons (vla-get-tagstring att) (vla-get-textstring att))) (vlax-invoke (vlax-ename->vla-object ename) 'getattributes)))

        (if (and
                (setq att (car (nentsel "\nSelectionnez UN Attribut a modifier: ")))
                (setq lst (entget att))
                (= (cdr (assoc 0 lst)) "ATTRIB")
                (numberp (read (cdr (assoc 1 lst))))    ;; Uniquement si le nombre correspond au premier caractère de l'attribut !
                (setq tag (cdr (assoc 2 lst)))
                (setq blc (entget (cdr (assoc 330 lst))))
                (setq name (getpropertyvalue (cdr (assoc -1 blc)) "BlockTableRecord/Name"))
                (princ "\nSelectionnez les Blocs a modifier ")
                (if (setq ss (ssget (list '(0 . "INSERT") (cons 2 (strcat name ",`*U*")))))
                        (repeat (setq n (sslength ss))
                                (if (and
                                        (wcmatch (getpropertyvalue (ssname ss (setq n (1- n))) "ClassName") "AcDbAssociative*Array")
                                        (/= (getpropertyvalue (ssname ss n) "BlockTableRecord/Name") name)
                                        (ssdel (ssname ss n) ss)
                                        (sssetfirst nil ss)
                        (princ "\nAucun jeu de sélection valide...")
                (setq add (getreal "\nEntrez la valeur a ajouter ou soustraire : "))
                (while (setq blc (ssname ss n))
                        (if (and
                                (assoc tag (setq att-list (get-att-list blc)))
                                (numberp (read (setq val (getpropertyvalue blc tag))))
                                        ((or (= (type (read val)) 'REAL) (= (type add) 'REAL))
                                                (setq txt (rtos (+ (read val) add)))
                                        ((and (= (type (read val)) 'INT) (= (type add) 'INT))
                                                (setq txt (itoa (+ (read val) add)))
                                (setpropertyvalue blc tag (strcat txt (vl-string-left-trim "0123456789." val)))
                        (setq n (1+ n))
                (princ "\nL Objet selectionne n'est pas un attribut ! ")


Meilleures salutations