How to edit the attribute values using AutoLisp

How to edit the attribute values using AutoLisp

Anonymous
Not applicable
1,302 Views
6 Replies
Message 1 of 7

How to edit the attribute values using AutoLisp

Anonymous
Not applicable

I want to change the values of a list of attribute tag's using to 'tagvalues' list.

the below program is to change the value of all attribute tag's to 'Nil'...

Can someone suggest how to rearrange this program to achieve it?

                    (setq tags (list "DRAWING_#" "V" "PH" "HZ" "SIZE"))
                     (setq tagvalues (list "A" "B" "C" "D" "E"))
                    (setq
                    ss (ssget "_x" (list '(2 . "TITLE_BLOCK_B-1")))
                    i 0
                    )    
                    (repeat (sslength ss)
                    (setq
                    obj (vlax-EName->vla-Object (ssname ss i))
                    lstatts (vlax-SafeArray->list (variant-Value (vla-GetAttributes obj)))
                    )
                    (foreach atts lstatts (if (member (vla-Get-TagString atts) tags)(vla-put-textstring atts "")))
                    (setq i (1+ i))
                    )

 

 

Thanks in advance.

0 Likes
Accepted solutions (3)
1,303 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

@Anonymous Test this: http://www.lee-mac.com/batte.html

0 Likes
Message 3 of 7

_gile
Consultant
Consultant
Accepted solution

Hi,

 

You shoud use an association list (e.g., a list of dotted pairs) instead of two separate lists.

 

(setq tagvalues '(("DRAWING_#" . "A") ("V" . "B") ("PH" . "C") ("HZ" . "D") ("SIZE" . "E")))
(setq
  ss (ssget "_x" (list '(2 . "TITLE_BLOCK_B-1")))
  i  0
)
(repeat (sslength ss)
  (setq
    obj     (vlax-EName->vla-Object (ssname ss i))
    lstatts (vlax-SafeArray->list (variant-Value (vla-GetAttributes obj)))
  )
  (foreach atts lstatts
    (if (setq pair (assoc (vla-Get-TagString atts) tagvalues))
      (vla-put-textstring atts (cdr pair))
    )
  )
  (setq i (1+ i))
)

 

Another way using the setpropertyvalue function:

 

(setq tagvalues '(("DRAWING_#" . "A") ("V" . "B") ("PH" . "C") ("HZ" . "D") ("SIZE" . "E")))
(if (setq ss (ssget "_x" (list '(2 . "TITLE_BLOCK_B-1"))))
  (repeat (setq i (sslength ss))
    (setq block (ssname ss (setq i (1- i))))
    (foreach pair tagvalues
      (vl-catch-all-apply 'setpropertyvalue (list block (car pair) (cdr pair)))
    )
  )
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 4 of 7

jayhar
Advisor
Advisor
Accepted solution

Hi,

Find the attachment

Please Subscribe YouTube Channel
https://www.youtube.com/channel/UCclj8v9vHQiFa8_DriuAk3w

Please Mark the Post or Posts as Solution(s) to help others find the answer quickly.
0 Likes
Message 5 of 7

Anonymous
Not applicable

Hi Gilles &  Jayhar,

Thanks for your quick response and it works well..

And sorry for the delayed communication.

0 Likes
Message 6 of 7

Anonymous
Not applicable

How to add a variable instead of values to paired list ?

(setq tagvalues '(("DRAWING_#" . VARAIBLE1) ("V" . VARIABLE2) ("PH" . "C") ("HZ" . "D") ("SIZE" . "E")))

 

0 Likes
Message 7 of 7

_gile
Consultant
Consultant
Accepted solution
(setq tagvalues
(list
(cons "DRAWING_#" VARAIBLE1)
(cons "V" VARIABLE2)
(cons "PH" "C")
(cons "HZ" "D")
(cons "SIZE" "E")
)
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes