Jump to content

Change block colour


liuhaixin88

Recommended Posts

Hello everyone!

A change block colour lisp by Lee Mac, Nice! support nested blocks, but only change block colour "byblock", I need change index colour(Pop-up color dialog)

(defun c:setbyblock ( / _byblock e )

   (defun _byblock ( n l / a e x )
       (if (and
               (setq e (tblobjname "BLOCK" n))
               (not (member n l))
           )
           (while (setq e (entnext e))
               (if (setq a (assoc 62 (setq x (entget e))))
                   (entmod (subst '(62 . 0) a x))
                   (entmod (append x '((62 . 0))))
               )
               (if (= "INSERT" (cdr (assoc 0 x)))
                   (_byblock (cdr (assoc 2 x)) (cons n l))
               )
           )
       )
       nil
   )

   (while
       (progn (setvar 'errno 0) (setq e (car (entsel "\nSelect Block: ")))
           (cond
               (   (= 7 (getvar 'errno))
                   (princ "\nMissed, try again.")
               )
               (   (= 'ename (type e))
                   (if (= "INSERT" (cdr (assoc 0 (entget e))))
                       (_byblock (cdr (assoc 2 (entget e))) nil)
                       (princ "\nObject is not a block.")
                   )
               )
           )
       )
   )
   (command "_.regen")
   (princ)
)

 

 

http://www.theswamp.org/index.php?topic=43457.msg486915#msg486915

 

In this page.Tharwat's code can Pop-up color dialog, but not support nested blocks.

Link to comment
Share on other sites

Try the following:

(defun c:setblockcolour ( / _blkcolour c e l )

   (defun _blkcolour ( n c / a e x )
       (if (and (setq e (tblobjname "block" n)) (not (member n l)))
           (progn
               (while (setq e (entnext e))
                   (entmod
                       (append
                           (vl-remove-if
                              '(lambda ( x ) (member (car x) '(62 420 430)))
                               (setq x (entget e))
                           )
                           c
                       )
                   )
                   (if (= "INSERT" (cdr (assoc 0 x)))
                       (_blkcolour (cdr (assoc 2 x)) c)
                   )
               )
               (setq l (cons n l))
           )
       )
       nil
   )

   (if (setq c (acad_truecolordlg 1))
       (progn
           (while
               (progn (setvar 'errno 0) (setq e (car (entsel "\nSelect Block: ")))
                   (cond
                       (   (= 7 (getvar 'errno))
                           (princ "\nMissed, try again.")
                       )
                       (   (= 'ename (type e))
                           (if (= "INSERT" (cdr (assoc 0 (entget e))))
                               (_blkcolour (cdr (assoc 2 (entget e))) c)
                               (princ "\nObject is not a block.")
                           )
                       )
                   )
               )
           )
           (command "_.regen")
       )
   )
   (princ)
)
 

 

Edited by Lee Mac
  • Like 1
Link to comment
Share on other sites

  • 7 years later...

Hello everyone!

This is very useful tool, but how could I change all the block colors in the drawing at one selection, e.g. window selection? / select all ?

Link to comment
Share on other sites

@CADTutor your forums wouldn't do people like that.

 

You can have things selected before you run this command. So i made a little lisp that selects all blocks in model space then runs this command.

;;----------------------------------------------------------------------------;;
;; CHANGES ALL BLOCK COLOR
(defun C:ALL_SETBLOCKCOLOR (/ SS)
  (if (setq SS (ssget "_X" '((0 . "INSERT") (410 . "Model"))))
    (progn
      (sssetfirst nil SS)
      (C:SETBLOCKCOLOR)
    )
    (prompt "\nNo Blocks in Model Space")
  )
  (princ)
)

 

This replaces the entity selection (one at a time) with and ssget so you can select multiple at a time. With the ssget it filters your selection down to blocks. So you don't have to be to precise with the selection window. just make sure only to select the blocks you want to change.

(defun C:SETBLOCKCOLOR (/ _blkcolour c e l)
  (defun _blkcolour (n c / a e x)
    (if (and (setq e (tblobjname "block" n)) (not (member n l)))
      (while (setq e (entnext e))
        (entmod
          (append
            (vl-remove-if
              '(lambda (x) (member (car x) '(62 420 430)))
              (setq x (entget e))
            )
            c
          )
        )
        (if (= "INSERT" (cdr (assoc 0 x)))
          (_blkcolour (cdr (assoc 2 x)) c)
        )
      )
      (setq l (cons n l))
    )
    nil
  )
  (if (and (setq c (acad_truecolordlg 1)) (setq SS (ssget ":L" '((0 . "INSERT")))))
    (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
      (cond
        ((= 7 (getvar 'errno))
            (princ "\nMissed, try again.")
        )
        ((= 'ename (type e))
            (_blkcolour (cdr (assoc 2 (entget e))) c)
        )
      )
    )
  )
  (command "_.regen")
  (princ)
)

 

 

Edited by mhupp
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Dear mhupp, the lisp works perfectly, sorry for being inattentive.

I used the original " C:SETBLOCKCOLOR  " not the one you send me.

Thank you very much

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...