'Change Entity's Layer Color' button
What would be the expected procedure to create a button which when after pressed and an entity is chosen, the entity's *layer* would be changed to a certain color ?
Comments
-
If you have a fixed colour (this uses colour 1) and you want to pre-select the entites try creating a toolbar button with:
^C^C_.chprop;_color;1;;
or if you want to choose the entities after the button click:
^C^C_.chprop;_color;\;1;;
but with the second option I think if you have PICKFIRST on and something it will not work properly.
Of course, another option would be to create a LISP function and assign that to the command button.
0 -
Hmmm.... I did not read your question very well :-(
Ok, you can create a toolbar button with ^C^CCHCOLOR if you load the LISP:
;; NOTE: I do not know anything about the "true colour" model
;; so this only works for standard colours.
(defun C:CHCOLOR ( / co en el ln le ll)
;; Get a single entity and change the colour of the layer
;; it is on.
;; The colour to change the layer to
(setq co 1) ; red
(if (setq en (car (entsel)))
(progn
;; get the entity data list
(setq el (entget en))
;; get the layer name
(setq ln (cdr (assoc 8 el)))
;; get the layer entity name
(setq le (tblobjname "LAYER" ln))
;; get the layer data
(setq ll (entget le))
;; change the layer colour
(setq ll
(subst
(cons 62 co)
(assoc 62 ll)
ll
)
)
(print ll)
;; modify the layer entity
(entmod ll)
)
)
(princ)
)Hope that was a little more helpful! :-)
0 -
I did not have much time earlier so here is a version that might be a little nicer...
;; NOTE: I do not know anything about the "true colour" model
;; so this only works for standard colours.
(defun C:CHCOLOR ( / co en el ln le ll errfunc oce oerr)
(defun errfunc (msg) ; error function
(if
(not
(member
(strcase msg)
'("CONSOLE BREAK"
"FUNCTION CANCELLED"
"QUIT / EXIT ABORT"
"")
)
)
(princ (strcat "\nError: " msg))
) ; endif
(setvar "CMDECHO" oce)
(command "._undo" "_end")
(if oerr (setq *error* oerr))
(princ)
) ;end error function
;; Save variables and set error handler
(setq oerr *error*
oce (getvar "CMDECHO")
*error* errfunc
)
(setvar "CMDECHO" 0)
(command "._undo" "_begin")
;; Get a single entity and change the colour of the layer
;; it is on.
;; The colour to change the layer to
(setq co 1) ; red
(if (setq en (car (entsel)))
(progn
;; get the entity data list
(setq el (entget en))
;; get the layer name
(setq ln (cdr (assoc 8 el)))
;; get the layer entity name
(setq le (tblobjname "LAYER" ln))
;; get the layer data
(setq ll (entget le))
;; change the layer colour
(setq ll
(subst
(cons 62 co)
(assoc 62 ll)
ll
)
)
;; modify the layer entity
(entmod ll)
)
)
;; Restore the variables, error handler and end the undo
(setvar "CMDECHO" oce)
(setq *error* oerr)
(command "._undo" "_end")
(princ)
)0 -
woosh! I'm such a newbie in bricscad that it took me forefer to learn a simple "(load chcolor.lsp)", but after I did - your proggy does exactly what I needed so thanks a bunch!
I'll go wrap this little code in nice button.
Thanks again
0 -
Look into the LISP autoload function and put a line in your on_doc_load.lsp if you want this routine loaded automatically only when needed.
Glad it worked for you.
0