Author Topic: Pick a Viewport and Change Xref Layer Color Using tblnext  (Read 1290 times)

0 Members and 1 Guest are viewing this topic.

CADworker

  • Mosquito
  • Posts: 2
Pick a Viewport and Change Xref Layer Color Using tblnext
« 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. 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.
Code: [Select]
(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.

BIGAL

  • Swamp Rat
  • Posts: 1411
  • 40 + years of using Autocad
Re: Pick a Viewport and Change Xref Layer Color Using tblnext
« Reply #1 on: August 19, 2020, 08:45:43 PM »
Look into
Code: [Select]
(foreach  match '("PL*V*HIDD" "ABCD" "XYZ")
............
)
A man who never made a mistake never made anything

tombu

  • Bull Frog
  • Posts: 289
  • ByLayer=>Not0
Re: Pick a Viewport and Change Xref Layer Color Using tblnext
« Reply #2 on: August 20, 2020, 09:07:34 AM »
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
Code: [Select]
(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.
Tom Beauford P.S.M.
Leon County FL Public Works - Windows 7 64 bit AutoCAD Civil 3D

CADworker

  • Mosquito
  • Posts: 2
Re: Pick a Viewport and Change Xref Layer Color Using tblnext
« Reply #3 on: August 20, 2020, 09:18:20 AM »
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.