TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: RGUS on August 10, 2018, 04:03:37 AM

Title: How to make Layer Control change color to ByLayer
Post by: RGUS on August 10, 2018, 04:03:37 AM
With entities gripped in the drawing editor, how do I then select a layer from the Layer Control pulldown and change the entities to not only the Layer picked but the colour to ByLayer?

Will this require adding some lisp or reactor of some type?

It would have been great if the Layer Control changed to not only the Layer, but to the color and linetype of that layer.

Any help or suggestions are appreciated.
Title: Re: How to make Layer Control change color to ByLayer
Post by: rkmcswain on August 10, 2018, 07:23:44 AM
The color drop down does include the BYLAYER choice.
Also, what about using the SETBYLAYER command?
Title: Re: How to make Layer Control change color to ByLayer
Post by: RGUS on August 10, 2018, 08:22:11 AM
The color drop down does include the BYLAYER choice.
Also, what about using the SETBYLAYER command?

Yes, these do the job, but they form a two pick operation.
The 'Layer Control" dropdown changes the entity to the selected layer but in name only, it does not change the entity color or linetype to that of the selected layer as well.

I just wondered if there was a 'one pick' way of doing all three things without having to write my own "Layer change" command.

Thanks for your suggestions.
Title: Re: How to make Layer Control change color to ByLayer
Post by: ronjonp on August 10, 2018, 08:39:40 AM
CNTRL+A then CNTRL+1 and make the changes in the properties palette.
Title: Re: How to make Layer Control change color to ByLayer
Post by: JohnK on August 10, 2018, 08:53:01 AM
-ch
All
P
C
Bylayer
Title: Re: How to make Layer Control change color to ByLayer
Post by: RGUS on August 10, 2018, 08:56:13 AM
CNTRL+A then CNTRL+1 and make the changes in the properties palette.

Thanks, Ron, this also does the job but as a multiple keyboard pick operation.
I guess Autodesk only intended the Layer Control pulldown menu to change the layer name only.
Looks like a special purpose routine to change gripped entity to layer_name, color_bylayer and linetype_bylayer from a list of layers in the drawing will be required.
A one pick operation.

Thank you for your help.
Title: Re: How to make Layer Control change color to ByLayer
Post by: RGUS on August 10, 2018, 09:02:41 AM
-ch
All
P
C
Bylayer

Thanks John
Title: Re: How to make Layer Control change color to ByLayer
Post by: ronjonp on August 10, 2018, 09:04:32 AM
Here's something that will work within blocks too:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ a c d)
  2.   ;; RJP » 2018-08-10
  3.     (cond ((= -1 (vlax-get l 'lock)) (vlax-put l 'lock 0) (setq a (cons l a))))
  4.   )
  5.     (if (= 0 (vlax-get b 'isxref))
  6.       (vlax-for o b (cond ((vlax-write-enabled-p o) (vla-put-color o 256))))
  7.     )
  8.   )
  9.   (foreach l a (vlax-put l 'lock -1))
  10.   (vla-regen d acallviewports)
  11.   (princ)
  12. )
Title: Re: How to make Layer Control change color to ByLayer
Post by: rkmcswain on August 10, 2018, 09:05:26 AM
Quote from: RGUS

I guess Autodesk only intended the Layer Control pulldown menu to change the layer name only.



Well, of course. Why would they make the LAYER control drop-down control, modify anything other than the LAYER?
Title: Re: How to make Layer Control change color to ByLayer
Post by: RGUS on August 10, 2018, 09:18:15 AM
Quote from: RGUS

I guess Autodesk only intended the Layer Control pulldown menu to change the layer name only.



Well, of course. Why would they make the LAYER control drop-down control, modify anything other than the LAYER?

LOL... so true... no sense in creating yet another "system variable" in case some punters also want to draw using color_bylayer and linetype.
I need to be more thankful to AutoDESK, I apologise for my query.
Title: Re: How to make Layer Control change color to ByLayer
Post by: rkmcswain on August 10, 2018, 09:28:35 AM
I guess I'm the one who is confused.

LAYER and COLOR are two separate properties.
It seems as if you expect that by changing the layer, AutoCAD should also set the COLOR property to BYLAYER?
Should it also set the linetype to bylayer? What about transparency and lineweight?



Title: Re: How to make Layer Control change color to ByLayer
Post by: ronjonp on August 10, 2018, 09:29:37 AM
Quote from: RGUS

I guess Autodesk only intended the Layer Control pulldown menu to change the layer name only.



Well, of course. Why would they make the LAYER control drop-down control, modify anything other than the LAYER?

LOL... so true... no sense in creating yet another "system variable" in case some punters also want to draw using color_bylayer and linetype.
I need to be more thankful to AutoDESK, I apologise for my query.
Set these two variable on startup and objects will default to be drawn linetype and color 'bylayer'.
Code: [Select]
(setvar 'celtype "bylayer")
(setvar 'cecolor "bylayer")
Title: Re: How to make Layer Control change color to ByLayer
Post by: JohnK on August 10, 2018, 09:41:04 AM
Here's something that will work within blocks too:
...

Here was something I wrote for ACAD 14--before vl--(doubt it worked within blocks though; and I don't remember autolisp enough to determine if it does) but it should work for all AutoCADs (windows or Mac).
Code - Auto/Visual Lisp: [Select]
  1. (defun colorByLayer (/ ss i elist)
  2.   (setq i -1)
  3.   (repeat
  4.     (sslength (setq ss (ssget "x" '((-4 . "/=") (62 . 256)))))
  5.      (entmod
  6.        (subst '(62 . 256) (assoc 62 (setq elist (entget (ssname ss (setq i (1+ i)))))) elist))
  7.   )
  8.   (princ)
  9. )