ScriptSpot

Forum topic · General Scripting

Hide Layer's Children

By Linkbird · 2015-03-08

Description

Hello, I'm looking to make a script that toggles hiding a layer whose name is, for example, "CAD"

I got a basic script working that hides it OK, but if the layer has sublayers, which in most cases it does, it hides the parent, but the sublayers' visibility remains unchanged.
I searched the help files but there is no getchildren, or something like that.
I'd really appreciate some help since I've been struggling with this one for a while.

Here's my script:

for i = 0 to (layermanager.count - 1) do
(
x = layermanager.getlayer i
layername = x.name as string
location = findString layername "CAD"
if location == 1 do
(
if x.on == true then x.on = false
else x.on = true
)
)

Comments (2)

.

miauu · 2015-03-10

If the names of the nested layers starts with "CAD" then their visibility state will be overwritten twice. Find a way to avoid that.
Build your own function to get all nested layers(nested layer in a nested layer in nested layer)


(
	for i = 0 to (layermanager.count - 1) do
	(
		x = layermanager.getlayer i
		layername = x.name as string
		if (matchPattern layername pattern:"CAD*") do
		(
			if x.on == true then 
				x.on = false
			else 
				x.on = true
			--	
			if (childLayersCnt = x.getNumChildren()) != 0 do
			(
				for j = 1 to childLayersCnt do
				(
					y = (x.getChild j)
					if y.on == true then 
						y.on = false
					else 
						y.on = true
				)
			)
		)
	)
)

Linkbird · 2015-03-11

Works like a charm! Thank you very much dude! Much, much appreciate it :)
I'll tinker around with it to get that extra functionality in it when I can and write the results here in case anyone else might find it useful.