Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm trying to trouble shoot a script, which has the objective of allowing a user to input a query for selected field, use the panToExtent function to pan the data frame at the specified scale to that feature, export as tiff, and then continue until the end of the features queried. This is the code I wrote:

import arcpy

#Set Overwrite Option
arcpy.env.overwriteOutput = True


mxd = arcpy.mapping.MapDocument("C:\\temp\\Graffiti_DM1.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "*")[0]
lyr= arcpy.mapping.ListLayers(mxd, "*", df)[0]

#USER INPUTS
lyr1="C:\temp\itscomplicated.shp"
query="Incident_Z" =="10006"
expdir="C:\temp\df"


for df in arcpy.mapping.ListDataFrames(query):
    df.rotation = 0
    df.scale = 1000
    outFile = expdir + df.name + ".tif"
    df.panToExtent(lyr.getSelectedExtent())
    arcpy.mapping.ExportToTIFF(mxd, outFile, df)
del mxd

Here is the traceback error:

Traceback (most recent call last):
  File "C:\temp\pantoextent.py", line 23, in <module>
    for df in arcpy.mapping.ListDataFrames(query):
  File "C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_
    return fn(*args, **kw)
  File "C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\mapping.py", line 1478, in ListDataFrames
    result = mixins.MapDocumentMixin(map_document).listDataFrames(wildcard)
  File "C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\arcobjects\mixins.py", line 727, in listDataFrames
    return list(reversed(list(self.dataFrames)))
  File "C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\arcobjects\mixins.py", line 694, in dataFrames
    return map(convertArcObjectToPythonObject, self.pageLayout.dataFrames)
  File "C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\arcobjects\mixins.py", line 678, in pageLayout
    return convertArcObjectToPythonObject(self._mxd._arc_object.pageLayout)
AttributeError: 'bool' object has no attribute '_arc_object'

Any help would be MUCH appreciated!

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

The error is about the variable 'query' used in ListDataframes. Check syntax.

You have [0] at the end of the first ListDataFrames, which will return only the first item in the listed dataframes. Thus, a loop won't do much good.

The wild card is used to narrow down the dataframes that will be listed by name.

What is your query? Are wanting to export the extent of all layers that have a field of Incident_Z with a value of 10006? If so, you will have to find another route (listing fields, search cursors, etc)

You define 'df, but your loop isn't going through 'df'. It is going through another ListDataFrames. To loop through df you would need to do something like:

for d in df:

I hope this helps you out some.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.