Select to view content in your preferred language

Labels Still Not Visible after setting lyr.labelClasses[0].showLabels = True

5696
20
Jump to solution
12-24-2013 10:05 AM
JonathanMulder
New Contributor III
Thanks to an earlier reply today, I'm moving along on my script but have encountered another hiccup.

I've set "lyr.showLabels = True".  After looking through some other threads, it looks like I also need to set labelClasses to "showLabels = True".  The script runs with no errors but does not show the labels.  When clicking on layer properties|Labels, it shows that the labelClasses[0].expression DID accept the StateWellNumber field.  But the checkbox for showing labels is not checked.

Is this "par for the course"?  Not a big deal (I can just go in and fill the checkbox), but it would be nice to see the labels come in as the script runs.

Thanks,

Jon Mulder 



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()
Tags (2)
0 Kudos
20 Replies
JonathanMulder
New Contributor III
Thanks Wayne,

I did find the replaceDataSource function and that was just what I needed.  I tried it on several data sources and works fine.  All datasources are created through a script so they will have the same properties.

I'm still learning here, but this is how I see it:


  • I am getting confused by a "layer" in a mapdocument dataframe as opposed to a "Layer" as referenced by "*.lyr". 

  • An in-memory layer is created by Arcpy for manipulation in a dataframe. 

  • This manipulation can include referring to a *.lyr" file. 

  • Manipulation on a dataframe "layer" are resident just for the session of the map document unless the map document is saved to a "*.mxd" or the layer is saved to a "*.lyr".

0 Kudos