3

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

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jul 19, 2016 at 14:41
6
  • Please review the code, since the last line seems mashed up Commented Jul 19, 2016 at 14:49
  • 3
    Your problem is likely the failure to either escape backslashes or to use "raw" mode (prepend an 'r' before the quote). So Python is correct -- the file "\...\TravisCountyAustinTxx.mxd\parks.shp" does not exist in directory "D:" Commented Jul 19, 2016 at 14:52
  • Code blocks must have FOUR leading spaces. There's a {} button to format it for you. Commented Jul 19, 2016 at 14:53
  • I tried the use r"D......shp" as well. No luck. The full error message is to follow. Commented Jul 19, 2016 at 14:56
  • 1
    Thank you for including the full error. Now look at what it says. An MXD is a file. No shapefile will be inside it as if it were a directory. Commented Jul 19, 2016 at 15:01

2 Answers 2

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
answered Jul 19, 2016 at 16:03
2

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"

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
answered Jul 19, 2016 at 16:49

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.