POST
|
I think I found the solution. The combination of the strip method and NOT having a "/" at the end of each folder path in the list (input file) made it work in all the folders this time. Here is the final code. import arcpy import os import sys os.chdir("u:\jthomas") f=open('testpaths.txt','r') for line in f.xreadlines(): #this next line appears to fix the problem of not entering first folders templine=line.strip() Workspace = templine arcpy.env.workspace = Workspace print Workspace mxdList = arcpy.ListFiles("*.mxd") print mxdList for file in mxdList: filepath=os.path.join(Workspace, file) print filepath mxd=arcpy.mapping.MapDocument(filepath) mxd.relativePaths = True mxd.save() print line f.close() input file format below g:\clientA\project1\GIS\Map Thanks For your help working through this Sephe Fox! I appreciate your help
... View more
04-21-2015
11:58 AM
|
2
|
1
|
1747
|
POST
|
Thanks. I tried that fix to the input file. I got the output below: r"G:\Clients\Liberty Groves - 1824\18240701-Liberty Groves\GIS\Map\Output_to_Hogle" None Runtime error Traceback (most recent call last): File "<string>", line 14, in <module> TypeError: 'NoneType' object is not iterable
... View more
04-21-2015
11:49 AM
|
0
|
0
|
1747
|
POST
|
BTW, I also tried using the following two lines to clean the file path. It worked in that the script starting working in the first folder I supplied. However once it got done with the first folder it throws an error on the line that 'for file in mxdList' templine=line.strip() Workspace = templine
... View more
04-21-2015
11:35 AM
|
0
|
0
|
356
|
POST
|
You mean inside the text file that has the lists of files?
... View more
04-21-2015
11:32 AM
|
0
|
4
|
1747
|
POST
|
Thanks - I just tried your suggestion. I inserted the print mxdList right after the line that sets up mxdList. It is printing a blank a line and the text, [] for each folder until it gets to the last folder. At that point it prints a list of file names (not full paths) inside the square brackets (see below). [u'file1.mxd', u'file.mxd', u'file.mxd'] So, it seems that it isn't getting a proper execution of the .ListFiles method until it hits the end of the folders in the input file.
... View more
04-21-2015
11:18 AM
|
0
|
7
|
1747
|
POST
|
Sorry - when I pasted in the code the tabs showed up as only single spaces. I typed in the tabs manually in the forum box this time so they show up better. import arcpy import os import sys os.chdir("u:\jthomas") f=open('testpaths.txt','r') for line in f.xreadlines(): Workspace = line arcpy.env.workspace = Workspace print Workspace mxdList = arcpy.ListFiles("*.mxd") for fileobj in mxdList: filepath=os.path.join(Workspace, fileobj) print filepath mxd=arcpy.mapping.MapDocument(filepath) mxd.relativePaths = True mxd.save() print line f.close()
... View more
04-21-2015
10:54 AM
|
0
|
9
|
1747
|
POST
|
I have a short script that reads a text file with a list of folders. For each folder it cycles through every MXD file and sets them to relative paths. For some reason the result of running this python script in the ArcCatalog command line is it only set MXDs to relative path in the last folder on my list. If my input list contains three file folders it only works on files in the third folder. If my input list contains 4 file folders it only works on those in the fourth folder. I added some Print commands to keep watch on the Workspace and filepath variables. This tells me that it correctly obtains the folder name every time but doesn't see the MXDs in the first folders. It appears that the inside loop is not running at all until it gets to the last iteration of the outside loop. I know I'm close to getting this to work but I am currently frustrated and would really appreciate your input! import arcpy import os import sys os.chdir("u:\jthomas") f=open('testpaths2.txt','r') # xreadlines methods used to access one row/line at a time from large text list of folder names for line in f.xreadlines(): Workspace = line arcpy.env.workspace = Workspace #print command used to watch current folder value print Workspace mxdList = arcpy.ListFiles ("*.mxd") for fileobj in mxdList: filepath=os.path.join(Workspace, fileobj) #print command used to watch filepath variable print filepath mxd=arcpy.mapping.MapDocument(filepath) mxd.relativePaths = True mxd.save() #print command used to watch line value print line f.close() The file 'testpaths2.txt' is a list of filepaths. Each filepath is followed by a hard return. Thanks, -j- Jason Thomas
... View more
04-21-2015
09:57 AM
|
1
|
12
|
6023
|
Title | Kudos | Posted |
---|---|---|
1 | 04-21-2015 09:57 AM | |
2 | 04-21-2015 11:58 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|