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...,.
Thanks, relevant code below.
for mxd_path in mxd_list: try: 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 = lyr.name ds = '-- X --' if lyr.supports('dataSource'): ds = lyr.dataSource lyr_attributes = [mxd_path, nm, ds] writer.writerow(lyr_attributes) else: if not lyr.isGroupLayer: arcpy.AddMessage('\nLayer {0} does not support the dataSource property'.format(nm)) unsupported.append(nm) lngnm = lyr.longName except Exception as e: arcpy.AddError('EXCEPTION: {0}\t{1}\t{2}'.format(mxd_path, lngnm, e)) continue writer.writerow(['']) del mxd
Solved! Go to Solution.
you need to be outside of the Geonet inbox...just open the message in a new tab. When you reply, in the upper right, there should be a "used advanced editor". Select that, and then there should be an attach icon in lower right corner .
to do a direct message, if we follow each other, then there will be a message option for you if you view my profile. There is a pull down version usually if you hover over my avatar too, but I do t see that right now on my device.
Thanks. I'll take a look at it later this week.
Sorry for the confusion in the last message. There isn't an attach on the DM. That was if we needed to take it offline with direct emails. (not enough coffee yet for a Monday morning)
Hi Greg,
Unfortunately, I didn't have much luck with your tools. After I fixed the source tot he python script, I ran it thru the Utilities toolbox and it said it ran successfully, but the .csv was never created.
The PyUtilities tool created the .csv file, but never seemed to finish, so I ended up cancelling it.
So unfortunately, I can't use either tool directly, but I do like some of your streamlined coding. Mine tends to get long, so I'm going to look to see if I can swipe any of your code to merge into mine. Thanks for sharing.