I'd like to use python to update the TOC by adding a space (white space) for layer names that are like this: "BoundaryBuffer" or "WaterEdge" and replace them with "Boundary Buffer" or "Water Edge".
I'm new to python and could use some assistance so far I've gotten to this but I can't get it to work correctly:
import arcpy >>> import re >>> mxd = arcpy.mapping.MapDocument("CURRENT") >>> df = arcpy.mapping.ListDataFrames(mxd) >>> layers = arcpy.mapping.ListLayers (mxd) >>> for lyr in layers: ... re.findall('[A-Z][a-z]*', lyr.name) ... arcpy.RefreshTOC()
I've looked at this post as well but I don't know how to integrate it with lyr.name in ArcGIS.
EDIT: I solved it myself! If anyone is interested or wants to comment:
import arcpy ... import re ... mxd = arcpy.mapping.MapDocument("CURRENT") ... df = arcpy.mapping.ListDataFrames(mxd) ... layers = arcpy.mapping.ListLayers (mxd) ... for lyr in layers: ... tempName = re.sub(r'([a-z])([A-Z])', r'\1 \2', lyr.name) ... lyr.name = tempName ... arcpy.RefreshTOC()