PYTHONPATH is a Windows (or UNIX) environment variable that needs to be set before the script is run, if you need it. The purpose of that variable is to modify sys.path when Python launches. Sys.path is a list of folders that tells Python where to look for imports, ie "import mymodule" will look for a file "mymodule.py" or "mymodule.pyc" through the sys.path, and use the first one it finds.It looks like you are trying to invoke the ntpath module. This module is already in the sys.path, so you could get to it with:import ntpathHowever, you don't need to import it -- the os module is what you want (and what you are using). I'm pretty sure os calls ntpath for you on windows, something else on Mac or Unix.If you need to alter where to look at runtime, you can alter the sys.path as follows. import sys sys.path.append(r"C:\mytools\python\modules")You can check out where imports will look by listing your sys.path: >>> import sys >>> sys.pathNote, by default, "" is the first item in sys.path. So if you include a custom module in the same folder as the script, it will always use that version.http://docs.python.org/tutorial/modules.html
import ntpath
import sys sys.path.append(r"C:\mytools\python\modules")
>>> import sys >>> sys.path
import arcpy, os #Parameters (workspaces) folderpath = arcpy.GetParameterAsText(0) oldpath = arcpy.GetParameterAsText(1) newpath = arcpy.GetParameterAsText(2) #Loop through folder for filename in os.listdir(folderPath): fullpath = os.path.join(folderPath, filename) if os.path.isfile(fullpath): basename, extension = os.path.splitext(fullpath) if extention.endswith("mxd"): mxd = arcpy.mapping.MapDocument(fullpath) mxd.findAndReplaceWorkspacePaths(oldpath, newpath) mxd.save()
import arcpy #Inputs mxdIn = arcpy.GetParameterAsText(0) #ArcMapDocument oldPath = arcpy.GetParameterAsText(1) #Workspace newPath = arcpy.GetParameterAsText(2) #Workspace #Set mxd mxd = arcpy.mapping.MapDocument(mxdIn) #Change workspace paths of layers mxd.findAndReplaceWorkspacePaths(oldPath, newPath) #Save mxd (overwrites mxd) mxd.save()
import arcpy, os PYTHONPATH = "C:\Python26\ArcGIS10.0\lib\ntpath.pyc" folderpath = arcpy.GetParameterAsText(0) oldpath = arcpy.GetParameterAsText(1) newpath = arcpy.GetParameterAsText(2) print 'running'
i=0 #create a folder within a local folder to store the mxds folderPath = r"" for filename in os.listdir(folderPath): fullpath = os.path.join(folderPath, filename) if os.path.isfile(fullpath): basename, extension = os.path.splitext(fullpath) if extension.lower() == ".mxd": mxd = arcpy.mapping.MapDocument(fullpath)
oldpath = "" newpath = r"" #mxd.replaceWorkspaces(oldpath, "SDE_WORKSPACE", newpath, "SDE_WORKSPACE",True) print "ok" mxd.findAndReplaceWorkspacePaths(oldpath, newpath) #mxd.save() mxd.save()
What is the particular error you are getting? Or does it run through without error and just not make any changes to the mxd?Also, posting your code with code blocks will make it easier for us to help.
I would try thismxd.saveACopy(file_name, {version})
mxd.saveACopy(file_name, {version})
PYTHONPATH = "C:\Python26\ArcGIS10.0\lib\ntpath.pyc"
PYTHONPATH = r"C:\Python26\ArcGIS10.0\lib\ntpath.pyc"
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.