Edit Block Attributes

Edit Block Attributes

T2oog
Explorer Explorer
512 Views
7 Replies
Message 1 of 8

Edit Block Attributes

T2oog
Explorer
Explorer

Hi,

I am new to the forum and to AutoLISP.  I have looked at several posts on this topic but they look more complicated than what I want, and I get confused.   If I can get some good detailed answers, it might help me begin to understand LISP better.

 

I have a block named, "1REV1".

It has the following tags:

MICROFILM

NO

DATE

1

BY

CHK'D

ENG

APP

 

To keep this simple for now, I only want to get the block (1REV1) and change the existing DATE attribute value (whether empty or not) to one defined in the LISP. 

 

Thank You,

 

New User

0 Likes
Accepted solutions (1)
513 Views
7 Replies
Replies (7)
Message 2 of 8

paullimapa
Mentor
Mentor

did you find this thread in your search:

Solved: EDIT ATTRIBUTE VALUE WITH LISP - Autodesk Community - AutoCAD


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

ВeekeeCZ
Consultant
Consultant

If there is only one of its kind in the drawing, not dynamic, here is your magic line. Tag is case-sensitive.

 

(setpropertyvalue (ssname (ssget "X" '((0 . "INSERT") (2 . "1REV1"))) 0) "DATE" one-defined-in-the-LISP)

0 Likes
Message 4 of 8

Sea-Haven
Mentor
Mentor
Accepted solution

Try this can replace newdate with say a get string for date or get current date from ACAD.

 

 

(defun wow (bname tagname newdate / ss1 x)
(setq ss1 (ssget "x"  (list (cons 0 "INSERT") (cons 2 bname)(cons 410 "model"))))
(repeat (setq x (sslength ss1))
   (foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS1 (setq x (1- x) ))) 'getattributes)
        (if (= tagname (strcase (vla-get-tagstring att)))
        (vla-put-textstring att newdate)
        )
   )
)
(princ)
)
(wow "1REV1" "DATE" "newdate")

 

0 Likes
Message 5 of 8

T2oog
Explorer
Explorer
It looks like a great example. I am just beginning and don't understand. I am ordering a book.
Thanks though
0 Likes
Message 6 of 8

T2oog
Explorer
Explorer
I will have a closer look at this one. Like my comment above, I have not yet put things together.
Thanks
0 Likes
Message 7 of 8

T2oog
Explorer
Explorer
This one runs when I open the drawing. It changes the "newdate" to whatever I enter in its place, such as "9/27/22". It does what I asked for, although maybe I would rater it run when I type "wow". I am new and have ordered a book with hopes of learning. Maybe other beginners will find this post helpful.

Thank You!
0 Likes
Message 8 of 8

Sea-Haven
Mentor
Mentor

Books are available on KINDLE very cheap, also Afralisp has a series of tutorials worth looking at.

 

Just add the lines like (setq date (getstring "\nEnter date xx/xx/xxxx ")) before the ssget and hard code the other variables bname and tagname.

 

Remove the passing variables at start (defun wow  / date ss1 x) ; note the localization of variables.

 

Good to see trying to learn you will get more help having a go rather than I want.

 

 

 

0 Likes