TransWikia.com

Symbology Layer is not being recognized by arcpy.ApplySymbologyFromLayer?

Geographic Information Systems Asked on December 4, 2020

The below arcpy.ApplySymbologyFromLayer call ran correctly before. But after I tried to test the script and the data within at a different location on the C drive it now fails with error code 000967.

To try to rule out data corruption I recreated the symbology layers from scratch but it still fails with the same code. I have also ensured that the path is relative and is pointing to the parent data and the symbology layer correctly. So now I am wondering if there is something else going on in my code that could be creating this issue.

for floor in theFloorList:
    if schMapping[theSchNum][0] == 'P':
        mxd = arcpy.mapping.MapDocument(os.path.join(os.path.dirname(sys.argv[0]), "Portrait_Maps.mxd"))
    else:
        mxd = arcpy.mapping.MapDocument(os.path.join(os.path.dirname(sys.argv[0]), "Landscape_Maps.mxd"))
    df = arcpy.mapping.ListDataFrames(mxd)[0]
    classroomSymbology = os.path.join(os.path.dirname(sys.argv[0]), 'Classrooms.lyr')
    buildingSymbology = os.path.join(os.path.dirname(sys.argv[0]), 'Buildings.lyr')
    floorSymbology = os.path.join(os.path.dirname(sys.argv[0]), 'Floors.lyr')
    classroomsWhere = "SchNum = {} and FLOOR_NAME = '{}'" .format(theSchNum, floor)
    floorsWhere = "Random_Sch_Num = {} and FLOOR_NAME = '{}'" .format(theSchNum, floor)
    buildingsWhere = "Random_Sch_Num = %d" % (theSchNum)

    for lyr in arcpy.mapping.ListLayers(mxd):
        if lyr.name == 'Student_Accounting':
            lyr.definitionQuery = classroomsWhere
            arcpy.ApplySymbologyFromLayer_management(lyr, classroomSymbology)
        if lyr.name == 'School_Floors':
            lyr.definitionQuery = floorsWhere
            arcpy.ApplySymbologyFromLayer_management(lyr, floorSymbology)
        if lyr.name == 'School_Buildings':
            lyr.definitionQuery = buildingsWhere
            arcpy.ApplySymbologyFromLayer_management(lyr, buildingSymbology)
            #Got information on getting extent of a layer and setting that extent to the data frame here: https://community.esri.com/thread/68673
            buildingsExt = lyr.getExtent()
            df.extent = buildingsExt

One Answer

I just found the solution and it ended up not directly relating to arcpy or python in general. I found that after moving the test folder into a new directory the layers within the mxd that I was referencing all had broken links. Therefore, when arcpy tried to apply symbology to the lyr object that I created it couldn't because that lyr could not point to the table of the feature class it represented. As soon as I went back to the mxd and fixed the links the script worked fine again.

Answered by Justin on December 4, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP