Jump to content

Change colour of ByLayer by selecting entity in drawing


woodman78

Recommended Posts

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.

Link to comment
Share on other sites

  • 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

(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)
)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

...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:
Link to comment
Share on other sites

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

Link to comment
Share on other sites

You didn't mention you were using Pantone/RGB colours. Those are a bit more complex. In such case I'd say the vla route would make for an easier way to adjust.

 

Edit: It is possible to work with these as well using entmod, but they are in the 430 and 420 code though: http://docs.autodesk.com/ACD/2011/ENU/filesDXF/WS1a9193826455f5ff18cb41610ec0a2e719-7a3d.htm

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)
)

Link to comment
Share on other sites

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...