I have a script that I am trying to move over to Pro but some process in the script don't run. The script has about 7 process, the script does not fail but it doesn't finish the last process witch applies smbologyfromlayer. For example the last process doesn't run when I run the script but if copy it into Pro's python window and hit enter it runs fine, it updates the symbology. I have tried reload(arcpy) and arcpy.ClearWorkspaceCache_management() before the arcpy.ApplySymbologyFromLayer_management process but it still doesn't work. Not sure what I am missing or not doing...
import arcpy, string, os
from importlib import reload
arcpy.env.overwriteOutput = True
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps()[0]
lyr = m.listLayers("TAXLOTS")[0]
lyt = aprx.listLayouts("Layout1")[0]
mf = lyt.listElements("MAPFRAME_ELEMENT")[0]
arcpy.env.workspace = os.path.dirname(aprx.filePath)
wp = os.path.dirname(aprx.filePath)
#selects PinID from TAXLOTS
values = arcpy.GetParameterAsText(0)
fieldName = "PinID"
values = values.split(";") # split values into list
values = ["'{0}'".format(v) for v in values] # add single quotes
whereClause = "{0} IN ({1})".format(fieldName, ",".join(values))
arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", whereClause)
#Udpates Text Element Template from layout
Name = arcpy.GetParameterAsText(1)
for lyt in aprx.listLayouts():
for elm in lyt.listElements("TEXT_ELEMENT","Text"):
if elm.text == "Template":
elm.text = (Name)
#Zooms to selected parcel in layout
ext = mf.getLayerExtent(lyr)
mf.camera.setExtent(ext)
mf.camera.scale *= 15
#Exports the selected parcels for SUBJECT_PROPERTY.
if int(arcpy.GetCount_management("TAXLOTS").getOutput(0)) > 0:
arcpy.Select_analysis("TAXLOTS", "SUBJECT_PROPERTY")
arcpy.SelectLayerByAttribute_management("TAXLOTS", "CLEAR_SELECTION")
#Remove layer
for m in aprx.listMaps():
print("Map: {0} Layers".format(m.name))
for lyr in m.listLayers("SUBJECT_PROPERTY"):
m.removeLayer(lyr)
#Add layer Subject_property
arcpy.env.workspace = os.path.dirname(aprx.filePath)
wp = os.path.dirname(aprx.filePath)
shp_path = wp + '\\' + "SUBJECT_PROPERTY.shp"
map = aprx.listMaps()[0] # assumes data to be added to first map listed
map.addDataFromPath(shp_path)
reload(arcpy)
arcpy.ClearWorkspaceCache_management()
#Update Subject Property symbology
#arcpy.env.workspace = os.path.dirname(aprx.filePath)
#wp = os.path.dirname(aprx.filePath)
#This arcpy.ApplySymbologyFromLayer_management doesn't update the layer symbology in the script
arcpy.ApplySymbologyFromLayer_management("SUBJECT_PROPERTY", wp + '\\'+ "Symbology_SUBJECT_PROPERTY.lyrx")
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>If I copy the last process into Pro python window in the same project and run it, it does update the symbology.
#Update Subject Property symbology
aprx = arcpy.mp.ArcGISProject("CURRENT")
arcpy.env.workspace = os.path.dirname(aprx.filePath)
wp = os.path.dirname(aprx.filePath)
arcpy.ApplySymbologyFromLayer_management("SUBJECT_PROPERTY", wp + '\\'+ "Symbology_SUBJECT_PROPERTY.lyrx")
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>