Jump to content

Change colour of ByLayer by selecting entity in drawing


Recommended Posts

Posted

Does anyone have a lisp that would allow me to select an entity in a drawing and the bylayer colour of that layer would change to 253. I have a lot of greying out to do and rather than going through the layer list I thought this might be easier.

  • Replies 27
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    8

  • woodman78

    5

  • Tharwat

    5

  • alanjt

    4

Top Posters In This Topic

Posted Images

Posted

(defun c:test ( / el i la ls ss )
   (if (setq ss (ssget))
       (repeat (setq i (sslength ss))
           (if (not (member (setq la (cdr (assoc 8 (entget (ssname ss (setq i (1- i))))))) ls))
               (progn
                   (setq el (entget (tblobjname "LAYER" la))
                         ls (cons la ls)
                   )                               
                   (entmod (subst (cons 62 253) (assoc 62 el) el))
               )
           )
       )
   )
   (princ)
)

 

Or single:

 

(defun c:test ( / e )
 (and
   (setq e (car (entsel)))
   (setq e (entget (tblobjname "LAYER" (cdr (assoc 8 (entget e))))))
   (entmod (subst (cons 62 253) (assoc 62 e) e))
 )
 (princ)
)

Posted

I tried both of them LeeMac but neither of them seem to work.

Posted

yeah, tried that but no joy.

Posted
yeah, tried that but no joy.

 

It's simple code, not much can really go wrong - are your layers colours not being changed?

Posted

No. It gives me the option to select something but then nothing happens. The colour remains the same and the item is set to bylayer.

Posted
No. It gives me the option to select something but then nothing happens. The colour remains the same and the item is set to bylayer.

 

Are your objects nested within blocks?

Posted

No wait. I was selecting hatch and it didn't work for that but it does work for lines. My bad.

Posted

Strange! It works perfectly on my 2011 (even using hatches).

 

Edit: Slight mod on Lee's code

(setq *SetLayerColor* 253)
(defun c:SetLayerColor (/ e c)
 (if (setq c (acad_colordlg *SetLayerColor* nil))
   (setq *SetLayerColor* c)
 )
 (while (and
          c
          (setq e (car (entsel "\nPick entity on layer (Enter to stop): ")))
          (setq e (entget (tblobjname "LAYER" (cdr (assoc 8 (entget e))))))
        )
   (entmod (subst (cons 62 c) (assoc 62 e) e))
 )
 (princ)
)

Allows for selecting a different colour, and also works "similar" to LayFrz. If you want it to work on nested entities change entsel to nentsel.

Posted

vla-put-color is the best way to deal with entities' colors .:)

Posted
vla-put-color is the best way to deal with entities' colors .:)

 

Why is that?

Posted

I have faced the issue which is the OP facing it right now with (cons 62 ......) and with entmod which is not working in some special cases that I also do not know why but with VLA*** it's been doing as needed.

Posted

If the object's color is set to bylayer there is no group 62. You must add in entities group 62 by (cons 62 . 253)

Posted

I think you guys are getting a little confused, we are not changing the colour of the entities, but the colour of the layers - these will always have a DXF 62 code.

 

The entities are only being selected to determine which layers need to be changed, the type of object selected should make no difference.

Posted
...but the colour of the layers - these will always have a DXF 62 code.
What? You mean you can't set a layer's colour to "ByLayer"???? :shock::roll:
Posted

If color adjustment layer, such as image, the color is not changed.

 

Wenn Layerfarbe Einstellung wie Bild, dann wird die Farbe nicht geändert.Bild 4.jpg

Posted
I have faced the issue which is the OP facing it right now with (cons 62 ......) and with entmod which is not working in some special cases that I also do not know why but with VLA*** it's been doing as needed.

Those issues generally only exist when trying to entmod certain properties of newer type entities (MLeader, etc.) or any annotative object, but color/layer/linetype are not of that list.

Posted

Oh yeah, here's a color one I did a while back (I took the lazy convert layer object to vla-object route) and a linetype one I did, but it requires DosLib....

 

(defun c:CLC (/ ss color i layer lst)
 ;; Change color of selected objects' layer
 ;; Alan J. Thompson, 07.23.09 / 05.16.11
 (if (and (setq ss (ssget)) (setq color (acad_colordlg 1 nil)))
   (repeat (setq i (sslength ss))
     (if (not (member (setq layer (cdr (assoc 8 (entget (ssname ss (setq i (1- i))))))) lst))
       (vla-put-color
         (vlax-ename->vla-object (tblobjname "LAYER" (car (setq lst (cons layer lst)))))
         color
       )
     )
   )
 )
 (princ)
)



(defun c:CLL (/ ss linetype i layer lst)
 ;; Change linetype of selected objects' layer
 ;; DosLib required (dos_linetypebox)
 ;; Alan J. Thompson, 05.16.11
 (if dos_linetypebox
   (if (and (setq ss (ssget)) (setq linetype (dos_linetypebox)))
     (repeat (setq i (sslength ss))
       (if (not (member (setq layer (cdr (assoc 8 (entget (ssname ss (setq i (1- i))))))) lst))
         (vla-put-linetype
           (vlax-ename->vla-object (tblobjname "LAYER" (car (setq lst (cons layer lst)))))
           linetype
         )
       )
     )
   )
   (progn (alert "DosLib must be loaded!")
          (command "_.browser" "http://www.en.na.mcneel.com/doslib.htm")
   )
 )
 (princ)
)

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...