Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Setting a definition query

$
0
0
Hi gang,

For some reason I can't get this code to work. I'm simply trying to set a definition query on a layer. The pertinent code is:

Code:

mxd = arcpy.mapping.MapDocument("CURRENT")

theProj = arcpy.GetParameter(1)

for lyr in arcpy.mapping.ListLayers(mxd):
    if lyr.name == theProj:
        lyr.definitionQuery = '"PROJ_TYPE" = \'C\' OR "PROJ_TYPE" = \'VC\''

The script runs fine, but no definition query is applied to the layer once it has completed.

Any help?


EDIT: I figured it out :D

Code:

mxd = arcpy.mapping.MapDocument("CURRENT")

theProj = arcpy.GetParameter(1)

for lyr in arcpy.mapping.ListLayers(mxd):
    if lyr.name == str(theProj):
        lyr.definitionQuery = '"PROJ_TYPE" = \'C\' OR "PROJ_TYPE" = \'VC\''


I had to add str() is all.

Viewing all articles
Browse latest Browse all 2485

Trending Articles