Definition Query

3584
10
04-19-2012 05:32 AM
StephenKruzik
New Contributor III
I know this probably the upteenth time a question like this has been asked, but my non-programming mind can't seem to wrap its head around it..

I'm using data driven pages to plot towersites in an area.  Each page goes to a new site based on it's SiteID.  I only want the map to show the site that I'm currently on.  Presently, it shows all of the sites, some of which are very close to the current one.  I ran through a stand alone script and it went through fine without any errors, but it didn't return the definition query, so the exported png still had all the sites on each map.

what am I doing wrong? 

[HTML]# Workspace
import os
import arcpy
import arcpy.mapping

mxd = arcpy.mapping.MapDocument("C:\GIS Data\Schuylkill\Validations.mxd")
mapLyr = arcpy.mapping.ListLayers(mxd, "Cell_Sites")[0]
carryElem = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT","Carriers")[0]

# activate data driven pages
ddp = mxd.dataDrivenPages
pageNum = ddp.currentPageID
print pageNum
contents = range(1,ddp.pageCount)
print contents

# set active view to first ddp, then iterate through each page
while pageNum in contents:

    print "we got to the while statement"

    # single out the one you are working on
    pageName = mxd.dataDrivenPages.pageRow.CellSiteID
    Exporter = mxd.dataDrivenPages.pageRow.LDTProvider
    df = arcpy.mapping.ListDataFrames(mxd, "Sites")[0]
    CurrentSite = arcpy.mapping.ListLayers(mxd, "Cell_Sites", df)[0]
    CurrentField = "CellSiteID"
    arcpy.MakeFeatureLayer_management("F:\GIS Data\Schuylkill County\Schuylkill MasterData.gdb\Validations\Cell_Sites", "IndexSites")

    for lyr in arcpy.mapping.ListLayers(mxd):
        if lyr.name == CurrentSite:
            lyr.definitionQuery = '"CellSiteID" = %s' % pageName[/HTML]

There is more after this, but for space conservation, I only pasted up to the def. query

As an aside, if you get me to where I need to be with this, and it works, I'll happily name a variable after you in my next script! 🙂
Tags (2)
0 Kudos
10 Replies
curtvprice
MVP Esteemed Contributor
  That is where I found the "AttributeError: object has no attribute '_arc_object'"  error being called.


Looking at the error message, I'm wondering if it's recognizing your layer LayerSite - though you'd think it would fail on your check

check = LayerSite.supports("DEFINITIONQUERY")


Might want to run this one by support.
0 Kudos