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
import arcpy.mapping
import os
OutFolderPath = "H:\Documents\GIS\HydstraData\HydstraMeasurementsDeep"
GeoDatabaseName = "HydstraMeasurementsDeep_GroundwaterElevation_Daily_Contours_20130625_20131015.gdb"
LayerFileLocation = "H:\Documents\GIS\HydstraData"
##Reference the Current map document.
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
##arcpy.env.workspace = GeoDatabaseName
arcpy.env.workspace = "H:\Documents\GIS\HydstraData"
##Add AllPoints Featureclass to map.
Wells_lyr = os.path.join(OutFolderPath,GeoDatabaseName,"AllPoints")
##print Wells_lyr
arcpy.AddMessage(Wells_lyr)
Wells_lyr = arcpy.mapping.Layer(Wells_lyr)
arcpy.mapping.AddLayer(df, Wells_lyr, "AUTO_ARRANGE")
##Add AllContours3D Featureclass to map.
Contours_lyr = os.path.join(OutFolderPath,GeoDatabaseName,"AllContours3D")
##print Contours_lyr
arcpy.AddMessage(Contours_lyr)
Contours_lyr = arcpy.mapping.Layer(Contours_lyr)
arcpy.mapping.AddLayer(df, Contours_lyr, "AUTO_ARRANGE")
##Apply symbology from layer files.
LayerName = os.path.join(LayerFileLocation,"CasedContours.lyr")
arcpy.AddMessage(LayerName)
arcpy.ApplySymbologyFromLayer_management("AllContours3D",LayerName)
LayerName = os.path.join(LayerFileLocation,"WellPoints.lyr")
arcpy.ApplySymbologyFromLayer_management("AllPoints",LayerName)
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
##Show labels for WellPoints.
Wells_lyr.supports("LABELCLASSES")
Wells_lyr.showLabels = True
Wells_lyr.labelClasses[0].expression = "StateWellNumber"
Wells_lyr.labelClasses[0].showLabels = True
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
Wells_lyr.labelClasses[0].showLabels = True
Wells_lyr.labelClasses[0].showClassLabels = True
Wells_lyr.labelClasses[0].expression = "[StateWellNumber]"
Wells_lyr.showLabels = True
Wells_lyr.labelClasses[0].expression = "\"StateWellNumber\""
import arcpy
import arcpy.mapping
import os
OutFolderPath = "H:\Documents\GIS\HydstraData\HydstraMeasurementsDeep"
GeoDatabaseName = "GSE_Daily_Contours_20130625_20131015.gdb"
LayerFileLocation = "H:\Documents\GIS\HydstraData"
##Reference the Current map document.
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
ws = os.path.join(OutFolderPath,GeoDatabaseName)
arcpy.env.workspace = ws
arcpy.AddMessage(ws)
##arcpy.env.workspace = "H:\Documents\GIS\HydstraData"
##Add AllPoints Featureclass to map.
Wells_lyr = os.path.join(OutFolderPath,GeoDatabaseName,"WellPoints")
##print Wells_lyr
arcpy.AddMessage(Wells_lyr)
Wells_lyr = arcpy.mapping.Layer(Wells_lyr)
arcpy.mapping.AddLayer(df, Wells_lyr, "AUTO_ARRANGE")
##Add AllContours3D Featureclass to map.
Contours_lyr = os.path.join(OutFolderPath,GeoDatabaseName,"AllContours3D")
##print Contours_lyr
arcpy.AddMessage(Contours_lyr)
Contours_lyr = arcpy.mapping.Layer(Contours_lyr)
arcpy.mapping.AddLayer(df, Contours_lyr, "AUTO_ARRANGE")
##Apply symbology from layer files.
LayerName = os.path.join(LayerFileLocation,"CasedContours.lyr")
arcpy.AddMessage(LayerName)
arcpy.ApplySymbologyFromLayer_management("AllContours3D",LayerName)
LayerName = os.path.join(LayerFileLocation,"WellPoints.lyr")
arcpy.ApplySymbologyFromLayer_management("WellPoints",LayerName)
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
##Show labels for WellPoints.
arcpy.AddMessage(Wells_lyr)
Wells_lyr.supports("LABELCLASSES")
Wells_lyr.showLabels = True
Wells_lyr.labelClasses[0].expression = "\"StateWellNumber\""
Wells_lyr.labelClasses[0].showClassLabels = True
arcpy.RefreshActiveView()
for lyr in arcpy.mapping.ListLayers(mxd):
arcpy.AddMessage( "Layer name: " + lyr.name)
if lyr.supports("LABELCLASSES"):
if lyr.showLabels:
arcpy.AddMessage( "Layer name: " + lyr.name)
for lblClass in lyr.labelClasses:
if lblClass.showClassLabels:
arcpy.AddMessage( " Class Name: " + lblClass.className)
arcpy.AddMessage(" Expression: " + lblClass.expression)
arcpy.AddMessage(" SQL Query: " + lblClass.SQLQuery)
for lyr in arcpy.mapping.ListLayers(mxd):
arcpy.AddMessage( "Layer name: " + lyr.name)
if lyr.supports("SHOWLABELS"):
arcpy.AddMessage(lyr.name + " supports labeling.")
arcpy.AddMessage("Layer labeling is on?: " + str(lyr.showLabels))
for lblClass in lyr.labelClasses:
arcpy.AddMessage( " Class Name: " + lblClass.className)
arcpy.AddMessage(" Expression: " + lblClass.expression)
arcpy.AddMessage(" SQL Query: " + lblClass.SQLQuery)
arcpy.AddMessage("Label class is on?: " + str(lblClass.showClassLabels))