BHenry85 Posted April 9, 2023 Posted April 9, 2023 I am trying to create some layerstates that will check to see if layers exist prior to making the changes to the properties on a list of layers, but when you use the VPLAYER command, the layer has to exist or it will throw an error and break the routine. I found a suggestion here, but I find that it doesn't work either. https://www.cadtutor.net/forum/topic/29171-check-to-so-if-a-layers-exists-if-so-do-something-if-not-skip/ Can someone review the attached file that I have provided and maybe provide some insight on where I went wrong? I thank everyone in advance for any assistance on this matter. Viewport Layerstates.lsp Quote
BIGAL Posted April 10, 2023 Posted April 10, 2023 (edited) You have almost answered your own question you can search the layer table for does it exist. So do a check and then do your IFS. BIt shorter than looking at every layer. So some suggestions. (if (tblsearch "Layer" layername) (princ "yes") (princ "No") ) Re IF's and but, it is better to do a (cond rather than individual IF's. (cond ((LayerWCMatch "FP1 - Appliances") (command "VPLAYER" "_thaw" "FP1 - Appliances" "C" "")) ((LayerWCMatch "FP1 - Attic Access")(command "VPLAYER" "_thaw" "FP1 - Attic Access" "C" "")) ............. ) Maybe ((tblsearch "Layer" "FP1 - Appliances") I dont think you can use a wildcard in searching layer names (TBLSEARCH "LAYER" "TEST22|C-ROAD-INTS") ((0 . "LAYER") (2 . "test22|C-ROAD-INTS") (70 . 48) (62 . 5) (6 . "Continuous")) (TBLSEARCH "LAYER" "*|C-ROAD-INTS") nil Wildcard not accepted So it may be better to add the xref name to the layer name being looked for. (tblsearch "Layer" (strcat xrefname "|FP1 - Appliances")) So would need to wrap the vplayer in a loop of Xref names. I tested on 500+ layers and it crashed. Using Tblsearch was instant return for xref layer. Just one last comment rather than having multiple If's or a cond can make a list of layer names and use a foreach. (foreach lay layerlst (setq nlayname (strcat xrefname "|" lay)) (if (tblsearch "Layer" nlayname) (command "VPLAYER" "_thaw" nlaynem "C" "") ) ) Edited April 10, 2023 by BIGAL Quote
BHenry85 Posted April 10, 2023 Author Posted April 10, 2023 @BIGAL Thank you so much sir. I will work through revamping my code and running some tests tomorrow then follow up if I have any issues and/or additional questions. Quote
Recommended Posts
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.