LayerFileLocation = "H:\Documents\GIS\HydstraData" LayerName = "WellPoints.lyr" ##Define layer: lyr = arcpy.mapping.Layer(os.path.join(LayerFileLocation,LayerName)) arcpy.AddMessage(lyr) ##Show labels for WellPoints. lyr.supports("LABELCLASSES") lyr.showLabels = True lyr.labelClasses[0].expression = "StateWellNumber" lyr.labelClasses[0].showLabels = True arcpy.RefreshActiveView()
Solved! Go to Solution.
WellPtsLyrFile = os.path.join(rootPath, 'WellPoints201312271743.lyr') Wells_lyr = arcpy.mapping.Layer(WellPtsLyrFile) ##Show labels for WellPoints. if Wells_lyr.supports("LABELCLASSES"): Wells_lyr.labelClasses[0].expression = "[StateWellNumber]" ## class labeling is on by default; showClassLabels is optional. #Wells_lyr.labelClasses[0].showClassLabels = True Wells_lyr.showLabels = True arcpy.mapping.AddLayer(df, Wells_lyr, "AUTO_ARRANGE")
import arcpy mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd") for lyr in arcpy.mapping.ListBrokenDataSources(mxd): if lyr.supports("DATASOURCE"): if lyr.dataSource == r"C:\Project\Data\Transportation.gdb\MajorRoads": lyr.replaceDataSource(r"C:\Project\Data\Transportation.gdb", "FILEGDB_WORKSPACE", "Highways") lyr.name = "Highways" mxd.saveACopy(r"C:\Project\Project2.mxd") del mxd
# fetches the layer from the map called WellPts from your defined mxd and df Wells_lyr = arcpy.mapping.ListLayers(mxd, "WellPts", df)[0] if Wells_lyr.supports("DATASOURCE"): # replaces WellPts source with the fc, NewWellPts, in YourFileGeodatabase.gdb Wells_lyr.replaceDataSource(r"C:\YourFileGeodatabase.gdb", "FILEGDB_WORKSPACE", "NewWellPts")