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.
Greg, for what it's worth, check out my Python addin for data inventory and “broken-link” repair.
I've had to deal with a lot of the same issues you had with groups, etc. To keep my files unique, I append the name with a datetime. I also write out to a .csv and a report, with an option for a FGDB (but never found a reason for it for my broken-link list).
I had some other tools on this toolbar, but decided to simplify is for sharing.
Greg, for what it's worth, check out my Python addin for data inventory and “broken-link” repair.
I've had to deal with a lot of the same issues you had with groups, etc. To keep my files unique, I append the name with a datetime. I also write out to a .csv and a report, with an option for a FGDB (but never found a reason for it for my broken-link list).
I had some other tools on this toolbar, but decided to simplify is for sharing.
Thanks Rebecca, will take a look after lunch!
Rebecca,
I'm able to use the tools from the toolbox, but the toolbar doesn't appear properly (image below). The tools themselves don't from there either, so it doesn't seem like links to the icon images being broken is the problem. Any ideas? Thanks
Greg, you didn't attach an image to your last reply.
Are you missing the tool buttons on my addin or on yours?
BTW - I'm working on a new version on my addin that exits cleaner if no mxd's are in the olders/subfolders, has better status checking thru procesing (x of y remaining message), now handles FGDB-standalone-tables, and fixes a flukey isCoverage test for my arctic_circle.shp (false positive with "\arc" as part of the name). Just an fyi.
Thanks Rebecca. The icons are showing up today (??), I'll check them out. When you update the addin, you may want to check the tooltip for 2 - Inventory. There are a couple of typos.
Thanks Greg. It doesn't surprise me that there are typos In the help/tooltips, etc. I throw quick notes in and I'm forget to go back and clean things up. I need to go thru to clean things up and add more details. I'm also kind of a hack (vs a hacker) when it comes to scripts....that is, not always pretty, but I just try to get it to work. However, I do try to include many comments (typos and all ). [note...many Geonet typos by me can be blamed on the iPad trying to second guess me....or just bad typing]
I had another tool the was that allowed a global drive change (e.g. 😧 to F:, or 😧 to a UNC) and then ran the broken link list again, but, although this worked, I decided that was a bit too broad a change and could creat new issues. I decided to only include a more controlled version with the fix links (4) script.
I'm not sure how far along with you script, but I had already been thinking about doing a complete mxd TOC inventor (not just broken links), and don't think it would be hard to change 3a to do this. I thought that would be a good addition to the toolbar. Not sure how detailed you were planning to get with your tool, but I'm hoping to add additional functionality to the addin, so if it something you want to share for that, let me know.
(note for those wondering what the 3a, 4, etc that I refer to....that is part on my script name In my addin...make it convenient for me 1) for me to know the order I usually run, and 2) sorts nice in my file-explorer and Wing projects.)
Sure, I'll share my script. I have two versions, one as a plain script tool, one as a python toolbox. I'm not sure how to post or send it, though, other than as an attachment to a post here.
I followed you, so you can send me a direct message with the attachment if you would like, or post it here.
I don't see a way to upload files, either in this box or thr message box. Only options are images or video. I suppose I could copy and paste the code, might be a little long though.