Here are two routines;
1. SetAttributeValue will do what you are asking.
Pass it the BLOCK handle, ATTRIBUTE tag name to change, new value
2. GetAttributeValue will return the value for a specified ATTRIBUTE tag in a
specified block. (just in case you need this one too)
Both routines use the routine GetDxfData, included.
;============================================================================
;============================================================================
(DEFUN SetAttributeValue (handle tag value / hndl ldat ltag llst)
(SETQ hndl handle)
(SETQ ltag(STRCASE tag))
(WHILE (/= "SEQEND" (GetDxfData 0 (ENTGET (SETQ hndl (ENTNEXT hndl)))))
(SETQ ldat(ENTGET hndl))
(IF (= "ATTRIB" (GetDxfData 0 ldat))
(IF (OR (/= "ATTDEF" (GetDxfData 0 ldat)) ; variable attribute: ATTRIB
(/= 0 (LOGAND 2 (GetDxfData 70 ldat)))) ; const: ATTDEF & const flag
(PROGN
(IF (= ltag (GetDxfData 2 ldat))
(PROGN
(SETQ llst(SUBST (CONS 1 value)(ASSOC 1 ldat) ldat))
(ENTMOD llst)
(ENTUPD hndl)
)
)
)
)
)
)
(REDRAW handle 1)
)
;=============================================================================
(DEFUN GetAttributeValue (handle tag / hndl ldat ltag)
(SETQ
hndl handle
ltag (STRCASE tag)
foundValue NIL
)
(WHILE (/= "SEQEND" (GetDxfData 0 (ENTGET (SETQ hndl (ENTNEXT hndl)))))
(SETQ ldat(ENTGET hndl))
(IF (= "ATTRIB" (GetDxfData 0 ldat))
(IF (OR (/= "ATTDEF" (GetDxfData 0 ldat)) ; variable attribute: ATTRIB
(/= 0 (LOGAND 2 (GetDxfData 70 ldat)))) ; const: ATTDEF & const flag
(IF (= ltag (GetDxfData 2 ldat))
(SETQ foundValue (GetDxfData 1 ldat))
)
)
)
)
(EVAL foundValue)
)
;============================================================================
(DEFUN GetDxfData (dxfCode entityData)
(CDR (ASSOC dxfCode entityData))
)
;============================================================================
Cheers,
Lu
//------------------------------------------------------------------
// When all else fails, read the book.
// CAD\Tek Home Page: http://www.cad-tek.com
//------------------------------------------------------------------
If you send me some detailed info. at de...@mid.org I see If I can come up with something quickly.
I have a routine that can update an attribute for every block on the drawing.
se ya
--
Mr. Desi Moreno http://www.invsn.com/desmos/autocad.htm
Engineering Technician
dmo...@vs1.invsn.com de...@mid.org
>How do you use autolisp to change block attributes? I am trying to write
>a program that updates the version number and date in a block. My only
>problem how do I get a hold of the attribute?
Just erase the first instance and re-insert the block passing the new value to
the attribute prompt.
Dennis Shinn
Seattle AutoCAD User Group
SAUG-BBS [206] 644-7115 [PCGNet]9:517/215
CAD Systems manager/GLY Construction
I have a AutoCad batch utility that includes some sample scripts to update
a title block. the script is designed so you select a list of drawings,
it loads each, updates the title block, and plots to a file based on
dimscale setting. it is real easy to modify the script to handle your
block definition. email me for more info.
--
James E. Toebes
toe...@spyder.net
Simplicity: The foundation of all complications
Select the block
use ENTNEXT to get the ATTRIB,
ENTGET to get the entity list,
SUBST to modify the value in the list
ENTMOD to modify the entity
>How do you use autolisp to change block attributes? I am trying to write
>a program that updates the version number and date in a block. My only
>problem how do I get a hold of the attribute?
>
>Please E-mail me; I don't get here very often.
>
>Thanks for the help!
>ME
>
There are different ways to do this. You can use the direct commands in
AutoCAD inside Autolisp to do this or using the the entity handling
functions. Use the "nentsel" and " "entnext" functions in the second case
to goto the desired attribute tag and value.
Also look out for some standard routines made available in the sites like
http://www.buildingweb.com/cadsyst
and many more.
G.Rajesh
//Autodesk Product Support on the Internet//
>How do you use autolisp to change block attributes?
We had a brief demo of a new product called Accuedit that will globally edit
text and block attributes *outside* of the drawing editor. Beta copies were
distributed to the attendees of our user group and I was told it was freely
distributable. If anyone would like a copy, drop me an email note and I'll
squirt one your way. (990kb self installing archive)
nb - only works with R12!
>How do you use autolisp to change block attributes? I am trying to write
>a program that updates the version number and date in a block. My only
>problem how do I get a hold of the attribute?
With an aid of some of my functions (that you may find on great Reini
Urban's site at http://xarch.tu-graz.ac.at/autocad/autolisp) we may
(setq edl (cdr(edlgetent blk-ename)))
;;list of entity-data lists
(setq atr-get-info (get '(2 . 1) edl ))
;;list of TAG-VALUE pairs
and
(setq atr-set-info
(mapcar 'cons (get 2 edl) edl))
;;list of TAG-DATALIST lists
We may now use ATR-GET-INFO for retrieving specific
tag's value with
(get "MYTAG" ATR-GET-INFO)
and set new value using ATR-SET-INFO with
(setq d (get "MYTAG" ATR-SET-INFO))
(enmod (subst '(1 . "NEWVALUE")(assoc 1 d) d)) etc...
Happy programming,
and don't forget to ENTUPD the head blk-ename!
--
Vladimir Nesterovsky ADS/LISP/C/C++ etc
<vne...@netvision.net.il>
ME,
What point are you at in the program? Are you able to extract any
information about the block at all? I'm just trying to get an idea where
your LISP knowledge is so I don't spend a lot of time rehashing what you
do know.
Sincerely,
Y-------------------------------------------------------------------+
| Darren J. Young | Minnesota CADWorks, Inc. |
| dyo...@mcwi.com | P.O. Box 7293 |
| 76341...@compuserve.com | St. Cloud, Minnesota 56302-7293 |
| http://www.mcwi.com | Phone: 1-320-654-9053 |
| CAD/CAM/CNC - Drafting Design Customization Training Programming |
0,0-----------------------------------------------------------------X
Email addresses not to be sold or used for unsolicited advertizments.