This is the script that will run without the running without line 28 that causes the error but is not adding the fields from the html field. I think I am missing something at 28 but when I had the recommended code I get error that it is not a valid command

AttributeError                            Traceback (most recent call last)
In  [5]:
Line 28:    update_layer = arcpy.mp.ListLayer(database + '\\' + FC)

AttributeError: module 'arcpy.mp' has no attribute 'ListLayer'
import arcpy, os

aprx = arcpy.mp.ArcGISProject("CURRENT")
input_parameter = r'c:\GIS_Working\zoning.kmz'
direct = os.path.dirname(input_parameter)
arcpy.conversion.KMLToLayer(input_parameter, direct)
arcpy.env.overwriteOutput = True

database = input_parameter[:-3] + 'gdb'
dataset = database + '\Placemarks'

arcpy.env.workspace = dataset
GCS_List = arcpy.ListFeatureClasses()
coord_sys = arcpy.SpatialReference('NAD 1983 StatePlane California V FIPS 0405 (US Feet)')
e_count = 0

for FC in GCS_List:
    arcpy.Project_management(FC, database + '\\' + FC + '_Proj', coord_sys)

    arcpy.env.workspace = database    
UTM_List = arcpy.ListFeatureClasses()

keep_fields = ['OID', 'Shape', 'SHAPE', 'Name', 'FolderPath', 'SymbolID', 'PopupInfo', 'Shape_Length', 'Shape_Area',]
for FC in UTM_List:
    update_layer = arcpy.mp.ListLayers(database + '\\' + FC)
    arcpy.mp.AddLayer(df, update_layer) 
SC = arcpy.SearchCursor(FC)

for row in SC:
    pop_string = row.getValue("PopupInfo")
    pop_array = pop_string.split("<")
    fields_array = []
    names_array = []
for tag in pop_array:
    if "td>" in tag and "/td>" not in tag:

for fields in arcpy.ListFields(FC):
    if fields.name not in keep_fields:
del fields_array[:2]

for x in range(0,len(fields_array)):
    if x%2 == 0 and fields_array[x] not in keep_fields:
        arcpy.AddField_management(FC, fields_array[x], "TEXT")


with arcpy.da.UpdateCursor(FC,names_array) as UC:
    for row in UC:
        pop_string = row[-1]
        pop_array = pop_string.split("<")
        fields_array = []
        values_array = []
    for segment in pop_array:
        if "td>" in segment and "/td>" not in segment:

del fields_array[:2]

for x in range(0,len(fields_array)):
    if x%2!=0:
        if fields_array[x-1] not in keep_fields:

for y in range(0,len(values_array)):
        row[y] = values_array[y]
    except IndexError:
            e_count = e_count + 1
  • 1
    arcpy.mapping (ArcMap) works differently to arcpy.mp (Pro) - many of the list functions have moved. But neither the ArcMap or Pro ListLayers method works for featureclasses in a workspace, they only work for Layers in a map.
    – user2856
    Apr 3, 2023 at 22:32
  • There is a field that comes over with an HTML string and I want to strip that out into fields with the data from the html. The script was from and old ArcMap/Python 2 script I found on here. It is copying the layer but not adding the fields and data to the field. Apr 3, 2023 at 23:28
  • @SonofaBeach nope, ListLayers is a method of a Map object, not a top level arcpy.mp function.
    – user2856
    Apr 4, 2023 at 4:05
  • How do I get the html out of the field and into new fields? Apr 4, 2023 at 21:25
  • @user2856 so that's a "yes" AND a "no". YES, it should have an "s" at the end of it (ie, ".ListLayers()", NOT ".ListLayer()", but NO, it is not "arcpy.mp.ListLayers()", nor "arcpy.mp.ListLayer()". Apr 4, 2023 at 23:25


Your Answer

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

Browse other questions tagged or ask your own question.