AutoLISP: Change Attribute Color to Bylayer (global)

I have used this routine a lot. I sometimes get drawings that have attributes that have had their color changed to something other than “BYLAYER.”  This routine will change all attributes colors to be BYLAYER.

Here’s How:

  • After loading, simply type in CHGATTCOL <enter> to start and it finishes from there.
Note: if you need to change both the geometry and attribute color to BYLAYER, use the SETBYLAYER command that is already in AutoCAD.

;change all attribute colors to bylayer

(defun C:ChgAttCol (/ name ss sslen cnt blck ent entinfo)

;(setq name (strcase (getvar "loginname")))

(setq ss (ssget "x" '((0 . "INSERT"))))

(setq cnt 0)

(setq sslen (sslength ss))

(while (< cnt sslen)

(setq blck (ssname ss cnt))

(setq ent (entnext blck))

(setq entinfo (entget ent))

(while

(and ent

(= (cdr (assoc 0 entinfo)) "ATTRIB")

)

(if (assoc 62 entinfo)

(entmod (subst (cons 62 256) (assoc 62 entinfo) entinfo))

)

(entupd ent)

(setq ent (entnext ent))

(setq entinfo (entget ent))

)

(setq cnt (1+ cnt))

)

(princ)

)
Advertisements

About AutoCAD Tips

This blog serves as a knowledge base for myself (and anyone else) so that I can reference tips & tricks that I have learned and also refer others to it as well. I hope that this blog helps you learn at least one tip to make your drafting/design experience better.
This entry was posted in Attributes, AutoLISP, Blocks, Modifying, Text, TIPS. Bookmark the permalink.

4 Responses to AutoLISP: Change Attribute Color to Bylayer (global)

  1. Joshua LUmley says:

    how do you change it to a color like “red”

  2. MS says:

    Thank You, nifty little code, helps cleaning up.

  3. Mario Gallardo says:

    This is an awesome routine. Thanks.
    Mario Gallardo

  4. Emi says:

    Why can I not use this lisp?
    I have error: bad argument type: lentityp nil.
    Anyone can help me please?
    Thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s