0

I am trying to geocode using ArcPy Python script in ArcGIS Pro and I keep getting this error:

Traceback (most recent call last): File "C:\Users\Owner\Desktop\Python Scripting for ArcGIS\finalproject\finalpython\Gecoding.py", line 10, in text_symbol = arcpy.mp.TextSymbol() AttributeError: module 'arcpy.mp' has no attribute 'TextSymbol'

Here is the full script

import arcpy
arcpy.env.workspace = r"C:\Users\Owner\Desktop\Python Scripting for ArcGIS\finalproject\finalproject.gdb"
arcpy.env.overwriteOutput = True
road_dataset = r"C:\Users\Owner\Downloads\Harford_County_Maintained_Roads_-3767853144656662417.csv"
road_name_field = "MD_iMAP_Composite_Locator"
output_point_fc = r"C:\Users\Owner\Desktop\Python Scripting for ArcGIS\finalproject\finalproject.gdb\Harford_County_GeocodeAddres"
geocode_result = r"C:\Users\Owner\Desktop\Python Scripting for ArcGIS\finalproject\finalproject.gdb\Harford_County_GeocodeAddres"
arcpy.MakeFeatureLayer_management(geocode_result, "RoadNamePoints_layer")
label_expression = "[" + road_name_field + "]"
text_symbol = arcpy.mp.TextSymbol()
text_symbol.font.size = 10
text_symbol.font.family = "Arial"
label_placement = "NO_OVERLAP"
label_point_placement = "UPPER_RIGHT"
arcpy.mp.AddLayer(arcpy.mp.ListDataFrames(arcpy.mp.MapDocument("CURRENT"))[0], "RoadNamePoints_layer", "AUTO_ARRANGE")
for lyr in arcpy.mp.ListLayers(arcpy.mp.MapDocument("CURRENT")):
    if lyr.name == "RoadNamePoints_layer":
        lblClass = lyr.listLabelClasses()[0]
        lblClass.expression = label_expression
        lblClass.textSymbol = text_symbol
        lblClass.placement = label_placement
        lblClass.position = label_point_placement
        arcpy.mp.refreshTOC()
        arcpy.mp.refreshActiveView()
        print("Geocoding and labeling completed.")
8
  • Traceback (most recent call last): File "C:\Users\Owner\Desktop\Python Scripting for ArcGIS\finalproject\finalpython\Gecoding.py", line 10, in <module> text_symbol = arcpy.mp.TextSymbol() AttributeError: module 'arcpy.mp' has no attribute 'TextSymbol' Commented May 16, 2024 at 4:41
  • 1
    That is correct, arcpy.mp has no attribute TextSymbol, have a look at pro.arcgis.com/en/pro-app/latest/arcpy/mapping/… and you'll find it's not in the list. I did find something that may help in CIM pro.arcgis.com/en/pro-app/latest/arcpy/mapping/… and search for labelClasses then call setDefinition on your label class theoretically, I've not done it myself. The only reference I can find for TextSymbol in ArcGIS belongs to an API other than arcpy. Commented May 16, 2024 at 4:52
  • well i need to use an arcpy for this project , if the code needs to be removed but still operates i don't mind that Commented May 16, 2024 at 4:57
  • 1
    You'll need to remove that, also lblClass.textSymbol doesn't exist, get rid of all those and replace with setDefinition (if it works), have a close look at the label class object (link in previous comment) to see what options are available. If not you can create a template feature class with the labels and symbology already defined, add the layer to the map and change the data source pro.arcgis.com/en/pro-app/latest/arcpy/mapping/… as if the layer is broken. Commented May 16, 2024 at 5:20
  • 1
    You're trying to use code based on ArcMap arcpy. You will also get an error with arcpy.mp.MapDocument which doesn't exist in Pro. ArcGIS Pro arcpy is different from ArcMap. See "Migrating from arcpy.mapping to ArcGIS Pro" Commented May 16, 2024 at 10:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.