Programmatically collapse layers in table of contents

969
3
07-17-2012 03:07 PM
GIS1
by
New Contributor II
Hi friends,

Does anyone have any ideas as to how I can collapse layers in my table of contents using a Python script? My current script grabs a MXD template, does a bunch of stuff, and saves a copy. Unfortunately a lot of the layers that begin minimized somehow get expanded and vice versa, and I can't figure out a way to control this. I know it's nitpicking, but it is helpful when you have a trillion things in the table contents to be able to collapse them all.

Thanks everyone!
Tags (2)
3 Replies
NumaGremling
New Contributor
Good question, and I have an answer for you, although not a python one, but it looks like you would be fine with just getting it done somehow.

Ok, so first you select all your layers. The shortcut to doing this is clicking on the first one, holding SHIFT, and then clicking on the last one. After that you click on one of the plusses/minusses while you're holding CTRL and all of your layers will expand/collapse.
0 Kudos
MathewCoyle
Frequent Contributor
There is no function available to arcpy to modify this property of a layer in an mxd that I know of in 10.x.

And in regards to the above solution, you don't need to select all the layers, just ctrl+mouseclick on the expand/collapse toggle button will do it.
0 Kudos
GIS1
by
New Contributor II
Good tips!

Too bad we can't control it with Python 😞

Thanks anyways!
0 Kudos