I need to adjust a premade .mxd many times, so I'd like to speed it up with this script. Everything is working except the Select by Location part.
The query reduce the Address layer to a single point and I want to use this point to select the layer. The mxd has all the county layers oppened but the input will change in the future.
I'm getting the error:ERROR 000368: Invalid input data. ERROR 000732: Selecting Features: Dataset Address does not exist or is not supported
If I run this script in ArcGIS with mxd set as "Current", then everything works.
I want to run the script without opening the actual mxd.
import os
import shutil
import glob, os
SID = "12234"
SIDtext = "df-" + str(SID)
address1 = "1233 Antler Dr"
address2 = "Summerton"
address3 = "23332"
address = address1 + "\n" + address2 + "\nSC " + address3
county = "Clarendon"
owner = "Smith"
test = "C:\\Users\\test\\test.mxd"
mxd = arcpy.mapping.MapDocument(test)
for df in arcpy.mapping.ListDataFrames(mxd):
#adjusting 1st dataframe
if df.name == "Overview Map":
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.name == "Address":
lyr.definitionQuery = "Case_ID = '" + str(SID) + "'"
#adjusting 2nd dataframe
else:
df2 = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
for lyr in arcpy.mapping.ListLayers(mxd, "Address", df2):
if lyr.name == "Address":
lyr.definitionQuery = "Case_ID = '" + str(SID) + "'"
df2.panToExtent(lyr.getSelectedExtent())
arcpy.SelectLayerByLocation_management(county, "INTERSECT", "Address")
arcpy.MakeFeatureLayer_management(county, "Property Parcel")
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.name == "Property Parcel":
lyr.visible=True
symbologyLayer = "Terra selection"
arcpy.ApplySymbologyFromLayer_management (lyr, symbologyLayer)
arcpy.SelectLayerByAttribute_management(county, "CLEAR_SELECTION")
arcpy.RefreshActiveView()
mxd.save()
del mxd
Error message:
Runtime error Traceback (most recent call last): File "", line 33, in File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\management.py", line 7320, in SelectLayerByLocation raise e ExecuteError: ERROR 000368: Invalid input data. ERROR 000732: Selecting Features: Dataset Address does not exist or is not supported
Address
layer? In yourif lyr.name == "Address"
add aprint lyr.name
to verify it is finding the layer – Midavalo♦ Feb 9 '17 at 2:39