• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

change color to a block

  • Thread starter Thread starter jim78b
  • Start date Start date

jim78b

Guest
I would like to make a script that clicking on a block totally changes the color independent from the layer... can you do it? ? ?
 
Is an unpretentious lisp okay?


;
(defun c:ccb (/ b_name col)
(setq b_name (cdr (assoc 2 (entget (car)))))))
(setq col (getstring "\nnumero colore: ")
(command "-bedit" b_name "_chprop" "_all"" "c" with ""_bclose "")
)
 
You just do it, but what good are you like you did to learn?? ? How do I get him to start copy the list and save him how? Don't slow down autocad?
 
for jim78b:
cover the list in a txt file, e.g. xyz.txt, save it and rename it in xyz.lsp.
at that point autocad launches and then the _appload command, the application loading window should appear, you look for your file and at that point it is usufructable like any other autocad command.
follow the instructions and change the color of the block.
or follow the tristan method.
I add that there is a section of the forum dedicated to the lisp, for questions about this subject do first research there and you will find all your answers.
Hi.
 
@jim78b, I'll answer you here.

the lisp I posted above asks for the selection of a block and the number of a color, after which passes to the command function a series of commands instead of giving them by keyboard:

- What? --> opens the block editorb_name --> block name saved in the variable b_name
_chprop -- Syrian command caprop_ --> select objects (all)
"" -- > Invio
c - > colour
col --> number of colour saved in the variable with
"" -- > Invio_bclose --> closes the block editor
"" -- > Inviowanting to change other properties of the block objects, you can add the instruction after opening the block editor (_bedit), for example wanting to change also the typeline of objects the lisp would look like this:

(defun c:chb (/ b_name col)
(setq b_name (cdr (assoc 2 (entget (car)))))))
(setq col (getstring "\nnumero colore: ")
(setq ntl (getstring) ")
(command "-bedit" b_name "_chprop" "_all" "" "c" col "" "_chprop" "_all" "_lt" ntl " "_bclose"
)

in red additional instructions.

to use the lisp:
- paste into a text editor
- save with .lsp extension
- appload command, select the file --> charge
- by command type chb

p.s. problems with irony?
 
I would need a lisp to change to just click the color of the block that is composed of several lines and layers.. It was in the past, but I can't find it.
 
you are right but using it if the block has a layer es layer 1 with blue color and I want red does not convert it as the layer 1 in color does not have bylayer!! !

I found out why, there are nested blocks... how can I do that? ? ?
 
I have updated the lisp of the other discussion, which, of course, changing the color to nested blocks the change is also reflected to all the others that contain them.
Code:
;;;cambia il colore ai blocchi nidificati
(defun c:ccb (/ cmd b_name col list_b en ed )
    ;***   gp 02/12/2011  ***

    (setq cmd (getvar "cmdecho"))
    (setvar "cmdecho" 0)           
    (command "_undo" "_begin")
    (setq b_name (cdr (assoc 2 (entget (car (entsel "\nselezionare il blocco "))))))
    (setq col (getstring "\nnumero colore: "))
    (setq list_b (cons b_name list_b))
    (setq b_def (tblsearch "block" b_name))
    (setq en (cdr (assoc -2 b_def)))
    (while en
        (setq ed (entget en))
        (if (= (cdr (assoc 0 ed)) "insert")
            (progn
                (setq b_name (cdr (assoc 2 ed)))
                (setq list_b (cons b_name list_b))
            )
        )
        (setq en (entnext en))
    )
    (repeat (setq n (length list_b))
        (setq b_name (nth (setq n (1- n)) list_b))
        (command "-bedit" b_name "_chprop" "_all" "" "c" col "" "_bclose" "")
    )
    (setvar "cmdecho" cmd)
    (command "_undo" "_end")
    (princ)
)
 
all you can reduce in:

(defun c:ccb2 (/ blocks block color)
(vl-load-com)
(setq blocks (vla-get-blocks (vla-get-activedocument))
block (vlax-ename->vla-object (car (entsel "\nselect reference block: ")
color (getint "\nscegliere colore: "
)
(vlax-map-collection)
(vla-item blocks (vla-get-name block)
'(lambda (elem)
(vla-put-color elem color)
)
)
(vl-cmdf "_regen")
)
 
ok would be nice even if selecting with a color autocad window for example red everything I choose
 
time ago kindly in the forum had created me this lisp that changed the color to the blocks ok is perfect but I would like the axes not to change color, usually I do them in green color I want them to remain such can you?

;;change color to nested blocks
(defun c:ccb (/ cmd b_name col list_b en e )
_

(setq cmd (getvar "cmdecho")
(setvar "cmdecho" 0)
(command "_undo" "_begin")
(setq b_name (cdr (assoc 2 (entget (car)))))))
(setq col (getstring "\nnumero colore: ")
(setq list_b (cons b_name list_b))
(setq b_def (tblsearch "block" b_name))
(setq en (cdr -2 b_def)))
(sing)
(setq and (entget en)
(if (= (cdr) "insert")
(progn)
(setq b_name (cdr (assoc 2 ed))))
(setq list_b (cons b_name list_b))
)
)
(setq en (entnext en)
)
(repeat (setq n (length list_b))
(setq b_name (nth (setq n (1-n)) list_b))
(command "-bedit" b_name "_chprop" "_all"" "c" with ""_bclose "")
)
(setvar "cmdecho" cmd)
(command "_undo" "_end")
(princ)
)
 
I have updated the lisp of the other discussion, which, of course, changing the color to nested blocks the change is also reflected to all the others that contain them.
Code:
;;;cambia il colore ai blocchi nidificati
(defun c:ccb (/ cmd b_name col list_b en ed )
    ;***   gp 02/12/2011  ***

    (setq cmd (getvar "cmdecho"))
    (setvar "cmdecho" 0)           
    (command "_undo" "_begin")
    (setq b_name (cdr (assoc 2 (entget (car (entsel "\nselezionare il blocco "))))))
    (setq col (getstring "\nnumero colore: "))
    (setq list_b (cons b_name list_b))
    (setq b_def (tblsearch "block" b_name))
    (setq en (cdr (assoc -2 b_def)))
    (while en
        (setq ed (entget en))
        (if (= (cdr (assoc 0 ed)) "insert")
            (progn
                (setq b_name (cdr (assoc 2 ed)))
                (setq list_b (cons b_name list_b))
            )
        )
        (setq en (entnext en))
    )
    (repeat (setq n (length list_b))
        (setq b_name (nth (setq n (1- n)) list_b))
        (command "-bedit" b_name "_chprop" "_all" "" "c" col "" "_bclose" "")
    )
    (setvar "cmdecho" cmd)
    (command "_undo" "_end")
    (princ)
)
Good morning to all, I would like to ask for information about this lisp, I tried it on some blocks and it works correctly, but some blocks that contain attributes, those remain of the original color, you can change it so that even the color of the attributes changes?
 
Actually, the attributes change color, but you have to sync them. you just type the attsync or sincatt command and will magically appear the color. without typing the command I allow me to add the synchronization line to the lisp of the good gp.

(defun c:ccb (/ cmd b_name col list_b en e )
_

(setq cmd (getvar "cmdecho")
(setvar "cmdecho" 0)
(command "_undo" "_begin")
(setq b_name (cdr (assoc 2 (entget (car) (entsel "\nsel select the block: ")))))
(setq col (getstring "\nnumero colore: ")
(setq list_b (cons b_name list_b))
(setq b_def (tblsearch "block" b_name))
(setq en (cdr -2 b_def)))
(sing)
(setq and (entget en)
(if (= (cdr) "insert")
(progn)
(setq b_name (cdr (assoc 2 ed))))
(setq list_b (cons b_name list_b))
)
)
(setq en (entnext en)
)
(repeat (setq n (length list_b))
(setq b_name (nth (setq n (1-n)) list_b))
(command "-bedit" b_name "_chprop" "_all"" "c" with ""_bclose "")
)
(vl-cmdf "_attsync" "n" b_name)
(setvar "cmdecho" cmd)
(command "_undo" "_end")
(princ)
)
 
Actually, the attributes change color, but you have to sync them. you just type the attsync or sincatt command and will magically appear the color. without typing the command I allow me to add the synchronization line to the lisp of the good gp.

(defun c:ccb (/ cmd b_name col list_b en e )
_

(setq cmd (getvar "cmdecho")
(setvar "cmdecho" 0)
(command "_undo" "_begin")
(setq b_name (cdr (assoc 2 (entget (car) (entsel "\nsel select the block: ")))))
(setq col (getstring "\nnumero colore: ")
(setq list_b (cons b_name list_b))
(setq b_def (tblsearch "block" b_name))
(setq en (cdr -2 b_def)))
(sing)
(setq and (entget en)
(if (= (cdr) "insert")
(progn)
(setq b_name (cdr (assoc 2 ed))))
(setq list_b (cons b_name list_b))
)
)
(setq en (entnext en)
)
(repeat (setq n (length list_b))
(setq b_name (nth (setq n (1-n)) list_b))
(command "-bedit" b_name "_chprop" "_all"" "c" with ""_bclose "")
)
(vl-cmdf "_attsync" "n" b_name)
(setvar "cmdecho" cmd)
(command "_undo" "_end")
(princ)
)
thank you so much for the help, and instead why does this block not change the color according to you? ?
 

Attachments

to me it changes, there was only one problem that, if in the drawing there were no blocks with attributes, it gave me an error message, even if the command ended regularly. Anyway, I solved it.

(defunc c:ccb (/ cmd b_name col list_b en ed ); [bleep]
(setq cmd (getvar "cmdecho")
(setvar "cmdecho" 0)
(command "_undo" "_begin")
(setq block (car (entsel "\nselect the block: ")
b_name (cdr (assoc 2 (entget block))
col (getstring "\nnumero colore: "
list_b (cons b_name list_b)
b_def (tblsearch "block" b_name)
(cdr (assoc -2 b_def))
)

(sing)
(setq and (entget en)
(if (= (cdr) "insert")
(progn)
(setq b_name (cdr (assoc 2 ed))))
(setq list_b (cons b_name list_b))
)
)
(setq en (entnext en)
)

(repeat (setq n (length list_b))
(setq b_name (nth (setq n (1-n)) list_b))
(command "-bedit" b_name "_chprop" "_all"" "c" with ""_bclose "")
)

(if (= (vla-get-hasattributes (vlax-ename->vla-object block)) :vlax-true)
(vl-cmdf "_attsync" (b_name)
)

(setvar "cmdecho" cmd)
(command "_undo" "_end")
(princ)
)
 
all you can reduce in:

(defun c:ccb2 (/ blocks block color)
(vl-load-com)
(setq blocks (vla-get-blocks (vla-get-activedocument))
block (vlax-ename->vla-object (car (entsel "\nselect reference block: ")
color (getint "\nscegliere colore: "
)
(vlax-map-collection)
(vla-item blocks (vla-get-name block)
'(lambda (elem)
(vla-put-color elem color)
)
)
(vl-cmdf "_regen")
)
hi, I ask one last thing, can you enter the command for synchronization of the attribute this lisp?
 

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top