AnsweredAssumed Answered

Python toolbox - check for nested group layers, and 2 more ?'s

Question asked by recurvata on Oct 7, 2015
Latest reply on Oct 20, 2015 by rastrauch

I have a python toolbox which crawls directories, or optionally a single mxd, and writes out various properties of the layers in them to a csv file, mostly interested in the data source. This works great, except...,.


  1. I check for group layers to skip those. The tool does skip top level group layers, but not group layers nested in other group layers. How can I skip those?
  2. I originally set a default location and file name for the output csv file, which the user can change. This works if the file doesn't already exist, but if it does, that parameter gets a big red X when the tool is run. The file is set to 'w', so I assumed it would just overwrite the existing file. Is it possible to do what I thought would happen?
  3. In the self.description in the __init__ function, I'd like to break the text on different lines and paragraphs. But no matter how many \n's I add, the tool ignores them when run, and collapses the text into one block. Is there a way to accomplish this?

Thanks, relevant code below.



for mxd_path in mxd_list:
        mxd = arcpy.mapping.MapDocument(mxd_path)
        dflist = arcpy.mapping.ListDataFrames(mxd)

        for df in dflist:
            for lyr in arcpy.mapping.ListLayers(mxd, '', df):
                if not lyr.isGroupLayer:
                    nm =
                    ds = '-- X --'
                    if lyr.supports('dataSource'):
                        ds = lyr.dataSource
                    lyr_attributes = [mxd_path, nm, ds]
                    if not lyr.isGroupLayer:
                        arcpy.AddMessage('\nLayer {0} does not support the dataSource property'.format(nm))
                        lngnm = lyr.longName
    except Exception as e:
        arcpy.AddError('EXCEPTION: {0}\t{1}\t{2}'.format(mxd_path, lngnm, e))
    del mxd