Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Layer color change by selecting object - need help with blocks

4 REPLIES 4
Reply
Message 1 of 5
mpa-la
638 Views, 4 Replies

Layer color change by selecting object - need help with blocks

I have the following lisp I got from Cadalyst that I really love. You can change a layer's color, including xref layers, by selecting an object and then typing in the new color. The only shortcoming is, when I click on a block, I would like the layer the block is inserted on to change, not the layer the block was created on, which is usually 0 in our office. Is there any way to change it (I'm not a programmer, post the code please :-)) so that it works that way? I have a feeling that if that is changed, then it won't work on xrefs anymore, it'll change the layer the xref was inserted on, but I wouldn't mind having two different commands, one for blocks, and one for everything else. Thanks in advance.

;;; CADALYST 04/08 www.cadalyst.com/code
;;; Tip 2278: XR-LAYCOL.LSP Change Xref Layer Color (c) 2008 Raymnond Rizkallah

;;;====================================================================
;;; [C:XRC] Function to change LAYER COLOR, extracting Layers name
;;; by picking objects.
;;;
;;; By Raymond RIZKALLAH - Oct./2007
;;;====================================================================
(defun C:XRC ()
(setq laylst nil)
(while
(setq entsll
(nentsel "\n Select object on the layer to be COLORED: ")
)
(setq laynam (cdr (assoc 8 (entget (car entsll)))))
(if (null laylst)
(setq laylst laynam)
(setq laylst (strcat laylst "," laynam))
)
(prompt (strcat "\n {" laylst "}"))
)
;end while
(if laylst
(progn
(setq lay-col (getint "\nNew Layers Color: "))
(command "layer" "c" lay-col laylst "")
)
)
;end if
(princ)
)
;end function
;;;====================================================================
(PROMPT "\n Use [C:XRC] to change XREF's layer COLOR.")
(PRINC)

4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: mpa-la


Change nentsel to entsel.  The n is for
"nested" entity selection, so it's finding the item inside the block, rather
than the block itself.

--
Kent Cooper

 

 


..... The only shortcoming is, when I click on a block, I would like the
layer the block is inserted on to change, not the layer the block was created
on, which is usually 0 in our office. Is there any way to change it (I'm not a
programmer, post the code please :-)) so that it works that way? .....

....

(defun C:XRC ()
(setq laylst nil)
(while
(setq entsll
(nentsel
"\n Select object on the layer to be COLORED: ")
)
....

Message 3 of 5
mpa-la
in reply to: mpa-la

Perfect, that's just what I needed!

Allison
Message 4 of 5
mpa-la
in reply to: mpa-la

I may be getting greedy, but do you think there's a way to change the layer color by picking a block in an xref, or are my only choices nested or not? In express tools there's that command that lists the properties of a block, and it works on blocks in xrefs, so there must be a way...
Message 5 of 5
Anonymous
in reply to: mpa-la


Well, a Block in an Xref is a nested entity,
too.  But it seems in trying it out that (nentsel) finds the deepest-level
nested entity, i.e. if you pick on a Line in a Block that's nested in an Xref
that's nested in another Xref, what it returns is the Line, not any of the
levels above that.  I'm not sure how to get at those, except in the Refedit
command, but I don't think that will do what you want.


face=Arial size=2>

--
Kent Cooper

 

 

I may be
getting greedy, but do you think there's a way to change the layer color by
picking a block in an xref, or are my only choices nested or not? In express
tools there's that command that lists the properties of a block, and it works on
blocks in xrefs, so there must be a way...

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost