How to add labels using arcpy

631
2
11-11-2019 09:48 AM
AnaVillaran
New Contributor

Hi community,

I am having problems to show the a Feature Layer label while exporting a Layout to a PDF File using a script tool on ArcGIS Pro.

As below, I've set the Label Class and expression, which seems to work on the application; however, when running this script which is producing a Map Book PDF the label for that feature is not shown until the Map Book PDF is exported.

# Create XY Coordinates Labels
XYCoordinates.showLabels = True

if XYCoordinates.supports("SHOWLABELS"):
    XYCoordinatesLblClass = XYCoordinates.listLabelClasses()[0]
    XYCoordinatesLblClass.expression = """'<FNT size="24">' + round($feature.POINT_X) + " " + round($feature.POINT_Y) + '</FNT>'"""""
    XYCoordinatesLblClass.visible = True

Is anyone having the same issue? I am also showing the GridIndexFeature labels produced by the Grid Index Features without a problem; so have no ideas as to why this specific one is not being shown until the PDF is produced.

Many thanks,

Ana

Tags (1)
0 Kudos
2 Replies
JeffBarrette
Esri Regular Contributor

Hello Ana,

Thank you for reporting this.  We just addressed this very recently (post 2.5 final).  Unfortunately, refresh isn't happening in the UI but you are seeing the correctly results in the export.  What I noticed is that if I manually interact with turning labels on/off and then run my scripts they work as expected.  I know this doesn't help with your automation but if you try toggling visibility manually by toggling on/off and then run your scripts, do you see the refresh?

Thanks,

Jeff

arcpy.mp team

AnaVillaran
New Contributor

Thanks Jeff, what you mentioned is what I ended up doing. Glad to know it has been addressed in 2.5

0 Kudos