Jump to content

change the same attribute - but in different named blocks


GISdude

Recommended Posts

Hi all,

I have a funky problem here in autocadlandia. I have several drawings that have about 15 different blocks. I have to change the color of ONE attribute in each block to "by layer". Right now they are set to "red". I found a wonderful LISP routine on lee-mac that will change the color - but you have to do it to each individual block - time consuming. The attribute is named the SAME ACROSS ALL THE BLOCKS - so I THINK this might be doable - but in the immortal words of my wife, "you're wrong." :)

 

Any ideas or tips is greatly appreciated.

 

And Terry if you're lurking...

 

Thx

Link to comment
Share on other sites

Hi,

Are you after changing the color of an attribute by tag name or by string ?

So can you specify that value?

Should the routine search over attributed block reference in a drawing or just by a certain block name ?

Finally. :) 

Are they dynamic block(s) or regular?

 

Link to comment
Share on other sites

The following will operate autonomously on the active drawing, modifying all attributes with tags matching the supplied pattern at the top of the code (this accepts wildcards):

(defun c:fixattcol ( / att atx col idx sel tag )

    (setq tag "TAG1" ;; Attribute tag(s) to change
          col 256    ;; New colour

          tag (strcase tag)
          col (list (cons 62 col))
    )
    (if (setq sel (ssget "_X" '((0 . "INSERT") (66 . 1))))
        (repeat (setq idx (sslength sel))
            (setq idx (1- idx)
                  att (entnext (ssname sel idx))
                  atx (entget att)
            )
            (while (= "ATTRIB" (cdr (assoc 0 atx)))
                (if (wcmatch (strcase (cdr (assoc 2 atx))) tag)
                    (if (entmod (append atx col))
                        (entupd att)
                    )
                )
                (setq att (entnext att)
                      atx (entget  att)
                )
            )
        )
    )
    (princ)
)

You can then run this across multiple drawings using my Script Writer program.

  • Like 1
Link to comment
Share on other sites

Hey Lee,

 

Thanks for putting this together. I have entered this code into VLISP (2018 - Map3D). I load it and the error keeps popping up, "Command: ; error: bad argument type: numberp: nil".

 

So, I went back to VLISP and used the debug tools. I am checking it using the "check text in editor" and this pops up,

[CHECKING TEXT fixattcol.lsp loading...]
.....
; error: bad function in expression: (1 - IDX)
.
; Check done.

Not sure what I'm doing wrong here. Thanks and I'll plug away at it a little more.

Link to comment
Share on other sites

Are you certain that you are using the code exactly as posted?

 

I ask as your quoted error is reporting an issue with the expression (1[space]-[space]IDX) whereas the posted code contains the expression (1-[space]IDX)

Link to comment
Share on other sites

Try the following routine and change the tag name that suits your desired one and regardless of any of the blocks that reside on locked layers.

(defun c:Test (/ *error* doc tag lst sel int ent)
  ;;------------------------------------;;
  ;; Tharwat - Date: 03.Oct.2019	;;
  ;; Change color of a certain attribute;;
  ;; based on its tag name to by layer.	;;
  ;;------------------------------------;;
  (defun *error* (msg)
    (and doc
         lst
         (foreach lay lst (vla-put-lock lay :vlax-true))
    )
    (and doc (vla-endundomark doc))
    (and msg
         (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")
         (princ (strcat "\nError =>: " msg))
    )
    (princ)
  )
  ;; change the tag to suit yours.
  (setq tag "My_Tag")
  ;;				;;
  (vla-endundomark
    (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  )
  (vla-startundomark doc)
  (vlax-for lay (vla-get-layers doc)
    (and (= (vla-get-lock lay) :vlax-true)
         (setq lst (cons lay lst))
         (vla-put-lock lay :vlax-false)
    )
  )
  ;;				;;
  (and
    (setq int -1
          sel (ssget "_X" '((0 . "INSERT") (66 . 1)))
    )
    (while (setq int (1+ int)
                 ent (ssname sel int)
           )
      (foreach att
               (vlax-invoke (vlax-ename->vla-object ent) 'getattributes)
        (and (= (strcase (vla-get-tagstring att)) tag)
             (vla-put-color att AcBylayer)
        )
      )
    )
  )
  (*error* nil)
  (princ)
)
(vl-load-com)

 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...