I'm trying to write a python script that runs a definition query. I'm having a problem with saving the query directly to a layer in a map document and not as its own layer file. Here is my code:
import arcpy import os import datetime #getting the right layer to modify mxd = arcpy.mapping.MapDocument(r"U:\FullPath.mxd") layerName = "BuildingFootprintsCopy" dataFrame = arcpy.mapping.ListDataFrames(mxd) print dataFrame layers = arcpy.mapping.ListLayers(mxd, layerName) print layers layerFromMap = arcpy.mapping.ListLayers(mxd, layerName, dataFrame) arcpy.mapping.AddLayer(dataFrame, layerFromMap, "AUTO_ARRANGE") #Definition Query date2 = datetime.date.today() - datetime.timedelta(days=730) print date2 dQueryVar1 = 'TOTAL_NUMB_FLOORS = ' + "2" dQueryVar2 = "DATE_BUILT >=" + " date " + "'" + str(date2) + "'" layerFromMap.definitionQuery = dQueryVar1 + " AND " + dQueryVar2 layerFromMap.save(mxd) #This is the line that throws the error. print "finished"
This is the error I'm getting:
Traceback (most recent call last): File "U:\TestDefinitionQueryWithDate.py", line 35, in <module> layerFromMap.save(mxd) File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\utils.py", line 182, in fn_ return fn(*args, **kw) TypeError: save() takes exactly 1 argument (2 given)
That returns the exact error. I'm not sure why I'm passing 2 arguments instead of 1. I've also tried :
That returns an error for not specifying a path.
How can I save my layer as the layer in the mxd I ran the definition query on and not as its own path? Can I save it in such a way that there is one layer with all of the data it originally contained with the definition Query on it?