[Closed] Exclude all nested layers within a specific layer
Hi guys
I have a script that switches layers on. Works great even for nested layers
lMask = "_"
fn switchOnObjectLayers =
(
for i = 0 to layerManager.count-1 do
(
local ilayer = layerManager.getLayer i
local lname = ilayer.name
-- Switch on all layers except for these: 0, Any layer starting with '_', any nested layer
if (((matchPattern lMask pattern:(substring lname 1 1)) != true) and (toUpper lname != toUpper "0") and (ilayer.getparent() == undefined)) then ilayer.on = true
)
)
However, I want to EXCLUDE ALL nested layers no matter how deep, from 1 specific layer called “MainLayer”. For the life of me I can’t seem to
find a way to do this seemingly simple thing
is it not easier to find a layer (protected) by name first, store its #on state, set all layer to value you want, and restore a protected layer ?
main = layerManager.getLayerFromName "MainLayer"
val = if main != undefined do main.on
for k=0 to layerManager.count -1 do (layerManager.getlayer k).on = state
if main != undefined do main.on = val
Hi Denis
Thanks for the reply. However I’m not sure I understand what you are saying
Running you code gives me this result:
– Error occurred in k loop; filename: ; position: 159; line: 3
– Frame:
– state: undefined
– k: 0
– Unable to convert: undefined to type: Boolean
<state> is what you want to set. it’s a pseudo parameter in my code… replace it with ON for example
if I for example declare state in the beginning as true, then I get an error about “on” being an unknown property…
We replied at same time
If I change it to “on” I still get:
Unknown property: “on” in undefined (line 4)
fn setAllLayersOn state =
(
for k=0 to layerManager.count-1 do (layerManager.getlayer k).on = state
)
fn setLayerOn name state =
(
if (layer = layerManager.getLayerFromName name) != undefined do layer.on = state
)
setAllLayersOn on
setLayerOn "MainLayer" off
I still get this error:
– Error occurred in k loop; filename: ; position: 103; line: 3
– Frame:
– k: 6
– called in setAllLayersOn(); filename: ; position: 103; line: 3
– Frame:
– state: true
– Unknown property: “on” in undefined
Thanks Denis
But that still pretty much works like I have it in my 1st code example
I need to exclude ”MainLayer” from being switched on as well as any nested layers inside it from being switched on. getparent and getchild gets me 1 layer deep only. Anything deeper and I can’t get it to work.
So I want to switch ON all layers including all nested layers, BUT EXCLUDING “MainLayer” and any nested layers inside it no matter how many levels deep