BrokenLegMike

Applying Definition Query to Layer

Discussion created by BrokenLegMike on Feb 20, 2014
Latest reply on Feb 25, 2014 by BrokenLegMike
I have some code that goes through and adds layers to a Map Document. I also want to apply definition queries to some layers:

arcpy.MakeFeatureLayer_management(dataSource,dataSource_lyr)
addLayer = arcpy.mapping.Layer(dataSource_lyr)
arcpy.mapping.AddLayer(df,addLayer)
if row.getValue("Definition_Query") <> None:
     addLayer.definitionQuery = "FIELD1" = 'Test'


I think I may be confusing myself, but I'm thinking I set a feature layer on a data source of some kind (arcpy.MakeFeatureLayer_management), and then set that feature layer to a layer object (arcpy.mapping.Layer) so that I have access to the layers properties? At that point, can I not use the addLayer variable to set a definition query?

When I go into the resulting ArcMap and look at the definition query, it's empty.

Outcomes