liuhaixin88 Posted April 20, 2014 Posted April 20, 2014 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. Quote
Lee Mac Posted April 20, 2014 Posted April 20, 2014 (edited) 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 July 3, 2019 by Lee Mac 1 Quote
liuhaixin88 Posted April 20, 2014 Author Posted April 20, 2014 Try the following: Thank you very much! Lee. Quote
filapost Posted December 29, 2021 Posted December 29, 2021 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 ? Quote
CADTutor Posted December 31, 2021 Posted December 31, 2021 Please note @filapost that this topic is now 7 years old. You may or may not get a reply. 1 Quote
mhupp Posted December 31, 2021 Posted December 31, 2021 (edited) @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 December 31, 2021 by mhupp 1 1 Quote
filapost Posted January 1, 2022 Posted January 1, 2022 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 Quote
Recommended Posts
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.