Having trouble getting my code to work. Keep getting IOError that my parks.shp doesn't exist....not sure I understand what this is saying.
import arcpy
mxd = "D:\...\TravisCountyAustinTxx.mxd"
mapdoc = arcpy.mapping.MapDocument(mxd)
dataset = "D:\...\TravisCountyAustinTxx.mxd\parks.shp"
spatialref = arcpy.Describe(dataset).spatialReference
extent = arcpy.Describe(dataset).extent
for df in arcpy.mapping.ListDataFrames(mapdoc):
df.spatialReference = spatialref
df.panToExtent()
df.scale = 15000
print "\nData frame " + df.name + " contains the following layers:"
lyrlist = arcpy.mapping.ListLayers(mapdoc, "", "", df)
for lyr in lyrlist:
print lyr.names
mapdoc.save()
del mapdoc
Full error message:
File "D:\Python27\ArcGIS10.2\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 325, in RunScript exec codeObject in main.dict File "D:\CLASSES\Debugging_andErrorHandlingLab\Scripts\Mod3_Script2_Template (2).py", line 12, in spatialref = arcpy.Describe(dataset).spatialReference File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy__init__.py", line 1234, in Describe return gp.describe(value) File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\geoprocessing_base.py", line 374, in describe self._gp.Describe(*gp_fixargs(args, True))) IOError: "D:\CLASSES\Debugging_andErrorHandlingLab\Data\TravisCountyAustinTxx.mxd\parks.shp" does not exist
2 Answers 2
LOTS OF ERRORS were fixed --.spatialRefernce (no good) .extent(no good), lyrlist, had too many arguments--FIXED
import arcpy
mxd = r"D:\CLASSES\Debugging_andErrorHandlingLab\Data\TravisCountyAustinTxx.mxd"
mapdoc = arcpy.mapping.MapDocument(mxd)
dataset = r"D:\CLASSES\Debugging_andErrorHandlingLab\Data\TravisCountyAustinTxx.mxd"
spatialref = arcpy.Describe(dataset)
extent = arcpy.Describe(dataset) df.scale = 15000
print "\nData frame " + df.name + " contains the following layers:"
lyrlist = arcpy.mapping.ListLayers(mapdoc, "", df)
for lyr in lyrlist:
print lyr.name
for df in arcpy.mapping.ListDataFrames(mapdoc):
df.panToExtent(df.extent)
mapdoc.save()
del mapdoc
Locate your shapefile.
The error message says it's in:
"D:\CLASSES\Debugging_andErrorHandlingLab\Data\TravisCountyAustinTxx.mxd\parks.shp"
The .MXD can't be a folder, so it's definitely not there.
Perhaps it's in the same folder as the MXD:
dataset = r"D:\CLASSES\Debugging_andErrorHandlingLab\Data\parks.shp"
{}
button to format it for you.