TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: CADworker on August 19, 2020, 02:22:06 PM
-
I'm looking for some help on how to get this working. I've been searching and found an older post, located here: https://www.theswamp.org/index.php?topic=42488.msg476831#msg476831 (https://www.theswamp.org/index.php?topic=42488.msg476831#msg476831). I would like to be able to do a table search for multiple layers and change their colors respectively but ignore those layers that don't exist. I need to be able to search for layers and change their color inside of a viewport for color plotting. This is what I have so far but it only works on one layer.
(defun c:try ()
(command "Tilemode" 0 "pspace")
(setvar "TileMode" 0)
(command "._MSPACE")
(setq UserVP (entsel "\nSelect Viewport to work on:"))
(COMMAND "._vplayer" "C" "137" "PL-V*HIDD" "select" uservp "" "")
(princ))
(defun c:OvrCol (/ en match)
(setq match "PL*V*HIDD") ;Save the wildcard match, since it's used more than once
(cond ((CheckLayerExists match)
(setvar "TileMode" 0)
(command "._PSPACE")
(if (progn (princ "\nSelect vieports: ")
(setq uservp (ssget '((0 . "VIEWPORT")))))
(command "._VPLAYER" "_Color" 137 match "_Select" uservp "" "")
(princ "\nNo viewports selected.")))
((princ (strcat "\nNo layers matching " match " exists, routine stopped."))))
(princ))
I would like to find other layers such as "PL-W*HIDD" and change the color to 46.
P.S. I'm somewhat new to LISP coding.
Any help would be appreciated.
-
Look into
(foreach match '("PL*V*HIDD" "ABCD" "XYZ")
............
)
-
Setting a Layer State inside a viewport creates viewport overrides for the layers defined in them by default.
Select an object on each of those layers, copy them to a blank drawing, modify the layer colors , create a Layer State which would only contain those layers, export to a las file and import it into drawings and templates as needed. Switching viewport overrides or simply removing them is just as easy.
I have a handful of Layer States in my templates I use every day. You have to make sure "Turn off layers not found in layer states" is unchecked so it doesn't turn off all the other layers. I've added(vl-registry-write (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\Profiles\\" (getvar "cprofile") "\\Dialogs\\AcLayerApps:LayerStatesManager") "LayerNotFound" "0")
to my acaddoc.lsp to make sure it's unchecked when a drawing is opened.
You do need to open the Layer States Manager to set them though. Using the Layer States ribbon drop-down or lisp functions ignore the Layer States Manager settings and would turn off all the other layers.
-
Thanks for the input.
BIGAL could you guide me on how to use the "foreach match"? I believe this sets each found layer to a variable, my question is how do I use that and change the layers respectively. Again, I'm somewhat new to lisp and I'm not familiar with the foreach function.