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

change layer of object to color not bylayer

12 REPLIES 12
Reply
Message 1 of 13
adham7
3039 Views, 12 Replies

change layer of object to color not bylayer

Hi,
I want a lisp to change all object colours from bylayer to its color
Example
(if layer doors its color is blue the color of objects drawn in this layer will by blue not bylayer)
thanks,
12 REPLIES 12
Message 2 of 13
Kent1Cooper
in reply to: adham7

I have to say I think that's a really bad idea, but assuming you have a legitimate reason to do it, this will:

{code}
(defun C:ECLC (/ ent obj)
;; = Entity Colors to their Layer's Color
(vl-load-com)
(setq ent (entnext))
(while ent
(setq obj (vlax-ename->vla-object ent))
(vla-put-Color
obj
(cdr (assoc 62 (tblsearch "layer" (vla-get-Layer obj))))
)
(setq ent (entnext ent))
); end while
); end defun
{code}

It will also change anything that already has a color other than Bylayer to the Layer's color instead.

--
Kent Cooper


adham7 wrote...
I want a lisp to change all object colours from bylayer to its color
Example
(if layer doors its color is blue the color of objects drawn in this layer will by blue not bylayer)
Kent Cooper, AIA
Message 3 of 13
diagodose2009
in reply to: adham7

See below ....bottom page
Message 4 of 13
stevor
in reply to: adham7

We did this for some dwg export reason, and the reverse.
Kent's code is much shorted, and its reverse seems to work:
{code}
; = Entity Colors to a Color number, or ByLayer; kent/s/27mar10
(defun C:ECLn (/ ent obj)
(if (and (setq cni (getint " Color Int, 256 for ByLayer "))
(and (< cni 257) (> cni 0)) )
(setq ent (entnext))
(princ " Out or 1-256 range ") )
(while ent
(setq obj (vlax-ename->vla-object ent))
(vla-put-Color obj cni )
(setq ent (entnext ent))
) (princ) ); end defun
{code}
S
Message 5 of 13
adham7
in reply to: adham7

thanks Kent1Cooper

But i want to select objects which i want to change its color, not all objects
Message 6 of 13
diagodose2009
in reply to: adham7

Here is http://www.megaupload.com/?d=LMV7EA6L
you can select any entities.
Message 7 of 13
stevor
in reply to: adham7

Staying on theme:
{code}
; selected Entity Colors to their Layer's Color kent/acm
(defun C:SCLC (/ ss obj si )
(princ"\n Select Ents to set color to layer color: ")
(if (setq si 0 ss (ssget))
(repeat (sslength ss )
(setq obj (vlax-ename->vla-object (ssname ss si)))
(vla-put-Color obj (cdr (assoc 62
(tblsearch "layer" (vla-get-Layer obj)))) )
(setq si (1+ si))
) )
(princ " Selectees: ") (prin1 (if ss (sslength ss) 0 ))
(princ) ) ; end defun
{code}
S
Message 8 of 13
Kent1Cooper
in reply to: adham7

I guess the wording "all objects" in the original question must have thrown me off...

I imagine stevor's suggestion would work. Here's how I would be inclined to do it:

{code}
(defun C:SECLC (/ ss obj)
;; = Selected Entity Colors to their Layer's Color
(vl-load-com)
(prompt "\nTo change their colors to their Layers' colors,")
(setq ss (ssget))
(repeat (sslength ss)
(setq obj (vlax-ename->vla-object (ssname ss 0)))
(vla-put-Color
obj
(cdr (assoc 62 (tblsearch "layer" (vla-get-Layer obj))))
)
(ssdel (ssname ss 0) ss)
); end repeat
); end defun
{code}

--
Kent Cooper


adham7 wrote...
.... i want to select objects which i want to change its color, not all objects
Kent Cooper, AIA
Message 9 of 13
adham7
in reply to: adham7

Thanks, very much
Message 10 of 13
brendon_butler
in reply to: adham7

I too have greatly benefited from this routine also...however, I'd like to go a step further if possible.

Can this routine be expanded in retaining the original linetype as well as the color?

 

Regards

Brendon

Message 11 of 13


@brendon_butler wrote:

... I'd like to go a step further if possible.

Can this routine be expanded in retaining the original linetype as well as the color?

....


If you mean you want to assign to every selected object the Linetype of its Layer as an override Linetype instead of Bylayer [untested]:

 

(defun C:SECLL (/ ss obj)
;; = Selected Entity Colors/Linetypes to those of their Layer
  (vl-load-com)
  (prompt "\nTo change their colors/linetypes to those of their Layer,")
  (setq ss (ssget))
  (repeat (sslength ss)
    (setq obj (vlax-ename->vla-object (ssname ss 0)))
    (vla-put-Color
      obj
      (cdr (assoc 62 (tblsearch "layer" (vla-get-Layer obj))))
    )
    (vla-put-Linetype

      obj
      (cdr (assoc 6 (tblsearch "layer" (vla-get-Layer obj))))
    )
    (ssdel (ssname ss 0) ss)
  ); end repeat
); end defun

Kent Cooper, AIA
Message 12 of 13
Anonymous
in reply to: Kent1Cooper

Sorry, to resurrect an old question. I'm assuming it's also possible to do the same for lineweights?

Regards,
Message 13 of 13
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:
Sorry, to resurrect an old question. I'm assuming it's also possible to do the same for lineweights?
....

Welcome to these Forums!

 

Yes, it is, though you need to "dig a little deeper," because (tblsearch) doesn't reveal the lineweight assigned to a Layer, the way it does the linetype.  You need to pull up the "entity data" for the Layer as an "object" rather than just an entry in the table of Layers, and get the value associated with 370 there:

 

    (vla-put-Lineweight

      obj
      (cdr (assoc 370 (entget (tblobjname "layer" (vla-get-Layer obj)))))
    )

Kent Cooper, AIA

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

Post to forums  

Autodesk Design & Make Report

”Boost