I have a script that (1) loops through a each row in a feature class; (2) creates temporary_layer_1 with the selected feature; (3) zooms to the extent of temporary_layer_1; (4) creates temporary_layer_2 with a matching field in a different feature class; (5) applies the symbology from each of the permanent (looped) layers to the corresponding temporary layers; and (6) exports the resulting map view as a PDF.
I've had success with the code on my laptop, running ArcMap 10.6.1. When I run the same code on my desktop, also 10.6.1, it fails at "arcpy.ApplySymbologyFromLayer_management," indicating that the input layer does not exist. What is puzzling is (1) that the input layer was already used successfully in the code in the previous lines, and (2) the layer types for input/output of ApplySymbologyFromLayer are identical, as one is the derivative of the other. After the processing fails, I try to run the failed line by dragging the input layer from the TOC into the Python window and it still fails. I've tried using the full file paths with no more success.
Failed to execute (Apply Symbology From Layer). Parameters are not valid. ERROR 000628: Cannot set input into parameter in_symbology_layer.
import arcpy import pandas as pd import numpy as np import os from arcpy.sa import * from arcpy import env gdb = r'C:\***\***.gdb' env.workspace = gdb env.overwriteOutput = True fc_2020 = 'basin_out' fc_2010 = 'basin_x' temp_2020 = 'basin_2020' temp_2010 = 'basin_2010' output_path = r'C:\**\**' mxd = arcpy.mapping.MapDocument('Current') df = arcpy.mapping.ListDataFrames(mxd) lyr = arcpy.mapping.ListLayers(mxd, fc_2020, df) with arcpy.da.SearchCursor(fc_2020, ['SHAPE@', 'Station']) as cursor: for row in cursor: station = str(row) arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", expression) ext = lyr.getSelectedExtent() ext.XMin = ext.XMin - 100 ext.YMin = ext.YMin - 100 ext.XMax = ext.XMax + 100 ext.YMax = ext.YMax + 100 df.extent = ext arcpy.RefreshActiveView() with arcpy.da.SearchCursor(fc_2010, ['SHAPE@', 'Number']): EXPRESSION = '"Number" = ' + station arcpy.MakeFeatureLayer_management(fc_2010, temp_2010, EXPRESSION) # make feature with only current 2020 row arcpy.MakeFeatureLayer_management(fc_2020, temp_2020) # temporary layer with the selected basin ### change symbology for each temporary layer arcpy.ApplySymbologyFromLayer_management(temp_2020, fc_2020) <-- **Failure Point** arcpy.ApplySymbologyFromLayer_management(temp_2010, fc_2010) arcpy.mapping.ExportToPDF(mxd, os.path.join(output_path, station + '.pdf'), resolution = 600, image_quality = 'BEST', colorspace = 'RGB', compress_vectors = True, image_compression = 'ADAPTIVE') arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION") arcpy.mapping.RemoveLayer(df, arcpy.mapping.ListLayers(mxd, temp_2020, df)) arcpy.mapping.RemoveLayer(df, arcpy.mapping.ListLayers(mxd, temp_2010, df))