Skip to main content
1 of 3

Selecting features through arcpy

I would like to achieve the following functionality through arcpy

  1. Querying an existing baselayer on time and create a new layer
  2. Apply symbology from an existing layer and add the new layer to the current session's data frame on top of the basemap

Have given my code below which gives me an Assertion Error when i try to add the layer returned from arcpy.MakeFeature. I am missing something trying to impact the current session. If i run the arcpy.MakeFeatureLayer_management command on the python console it works fine. But I am not able to get it work through the scripts in the toolbox. Please advice me on this.

import arcpy
arcpy.env.overwriteOutput = True
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "*")[0]
arcpy.MakeFeatureLayer_management ("base_layer", "new_layer_1","DATE_TIME" = TO_DATE('13-JUL-2010 12:40:00','DD-MON-YYYY HH24:MI:SS'))
arcpy.ApplySymbologyFromLayer_management("out_time",r"C:\WIP\Shape files\KARTHIK.TEST_TABLE.lyr")
arcpy.mapping.AddLayer(df,out_time)
arcpy.RefreshActiveView()