1

I am teaching myself ArcPy and I am attempting to make a code to replace paths to the items in my workspace. I had a file geodatabase and its path changed so I would like to automatically modify the path with ArcPy.

>>> mxd=arcpy.mapping.MapDocument("CURRENT")
>>> arcpy.mapping.MapDocument.findAndReplaceWorkspacePaths(r"E:\GIS\_Wolverine Time\ArcGIS\California_DrinkingWater\Cali2.mdb",r"E:\GIS\California_DrinkingWater\Cali2.mdb")

I thought it was that simple but I received the following error:

Runtime error 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: unbound method findAndReplaceWorkspacePaths() must be called with MapDocument instance as first argument (got str instance instead)
4

Instead of calling arcpy.mapping.MapDocument.findAndReplaceWorkspacePaths(...), have you tried calling mxd.findAndReplaceWorkspacePaths(...)?

Calling the function from the object you created (mxd) ensures that ArcPy knows which map document you are working with, whereas the code you have doesn't specify the map document (your are calling the unbound method, meaning it is not associated with a map document object). I can't find any documentation for calling the unbound method directly, but I would assume since it is not being called on a specific map document, it is expecting you to specify one as your first argument.

  • 1
    you could lengthen this (which we like here) by explaining the difference and why it would answer the question. – Brad Nesom Jun 25 '15 at 15:17
  • Thank you @BruceDoh. It worked. Now I know what 'unbound' means. Really glad it was that simple! – WolverineTime Jun 25 '15 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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