Changing attributes color to a given number

Discussion in 'AutoCAD' started by A Diaz, Feb 9, 2004.

  1. A Diaz

    A Diaz Guest

    Hello,

    I am trying to change the attribute color to a given number. I have several
    drawings with a lot of blocks with attributes using color ByLayer. I want to
    globally change the color of my attributes to a different color. I did
    modified a code I found in this newgroup 2 years ago, but this is not
    working.
    Here is the code:

    (defun C:ChgAttColorToOther (/ name ss sslen cnt blck ent entinfo)
    (setq name (strcase (getvar "loginname")))
    (initget 7)
    (setq AttribColor (getint "\n\nEnter New Attribute Color <11>: "))
    (terpri)
    (cond ((not AttribColor) (setq AttribColor 11)))
    (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 AttribColor) (assoc 62 entinfo) entinfo))
    )
    (entupd ent)
    (setq ent (entnext ent))
    (setq entinfo (entget ent))
    )
    (setq cnt (1+ cnt))
    )
    (princ)
    )


    What's wrong?
    TIA
     
    A Diaz, Feb 9, 2004
    #1
  2. A Diaz

    A Diaz Guest

    I found that the lisp works fine for block where the attribute is not color
    ByLayer. Any idea?
     
    A Diaz, Feb 9, 2004
    #2

  3. If I remember correctly ...

    Code 62 does not exist when the color if BYLAYER. If that is so then you
    will need to add an else expression as shown in the code below.

    (if (assoc 62 entinfo)
    (entmod (subst (cons 62 AttribColor) (assoc 62 entinfo) entinfo))
    ;else ...
    (append entinfo (cons 62 AttribColor))
    )


    Andy
     
    Andy Freeland, Feb 9, 2004
    #3
  4. correction ...

    (setq entinfo (append entinfo (cons 62 AttribColor)))


    Andy
     
    Andy Freeland, Feb 9, 2004
    #4
  5. A Diaz

    A Diaz Guest

    Thank you Andy.
    The code will be like this:

    (if (assoc 62 entinfo)
    (entmod (subst (cons 62 AttribColor) (assoc 62 entinfo) entinfo))
    (setq entinfo (entmod (append entinfo (list (cons 62 AttribColor)))))
    )
     
    A Diaz, Feb 9, 2004
    #5
  6. ah yes ... you are correct.
     
    Andy Freeland, Feb 9, 2004
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.