Yes.
Not working/old path: \\Jackson\gis_dept\Data\Images\County-logo-1x1Small.JPG
Working/new path: P:\Images\County-logo.JPG
I thought it wouldn't be bad either? The script I posted above, and again here, seems nice. But it doesn't want to work in a case where the path is broken. So, line 3 is calling the mxd I zipped above. And, as noted, because of the broken path, the pictures aren't in the mxd. That's why I think this script isn't working. In other words, I think the pictures have to be there for the script to work.
Description: find a picture element using a wildcard and then change the picture's data source
<SPAN class="keyword token">import</SPAN> arcpy mxd <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>MapDocument<SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">'R:\AtlasMaps\ATLAS_MAPS_17\New folder\1st_District_B2.mxd'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> elm <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ListLayoutElements<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"GRAPHIC_ELEMENT"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"*logo*"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">if</SPAN> elm<SPAN class="punctuation token">.</SPAN>name <SPAN class="operator token">==</SPAN> <SPAN class="string token">'County-logo-1x1Small'</SPAN><SPAN class="punctuation token">:</SPAN> elm<SPAN class="punctuation token">.</SPAN>sourceImage <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'P:\Images\County-logo.JPG'</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">'{} changed'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>elm<SPAN class="punctuation token">.</SPAN>sourceImage<SPAN class="punctuation token">)</SPAN> mxd<SPAN class="punctuation token">.</SPAN>saveACopy<SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">'R:\AtlasMaps\ATLAS_MAPS_17\New folder\1st_District_B3.mxd'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">del</SPAN> mxd<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Taken from here: ListLayoutElements—Help | ArcGIS for Desktop
Hm, that is interesting. I'll keep that in mind.
Hi Jared,
Can you open you map and check to make sure your picture element is still named?
Alternatively, instead of checking against the name property of the picture element, you could always check against the current imageSource property is "" \\Jackson\gis_dept\Data\Images\County-logo-1x1Small.JPG" and if so then change to r'P:\Images\County-logo.JPG'.
Unfortunately there is no method in arcpy for checking if Picture Elements to see if the link is no longer valid. There is probably some python module somewhere that could do this and could be used in conjunction with arcpy to check and update picture element paths
I haven't tried to test for graphic elements, but I can take a look at this later (probably not until later this week). I know I have a few more types of broken links I wanted to test for, but have moved off of that project for the time being, and since it does about 98%.
I may have a newer version and better description of my addin on this page, fwiw.
/blogs/myAlaskaGIS/2015/08/31/python-addin-for-data-inventory-and-broken-link-repair
Can you zip you mxd and attach it? all items will be broken of course for me, but it will give me something to test. Thanks.
@Rebecca
This is a great addin. I just tried it and It works fine for listing broken source data. But, my problem is, I need to list broken picture elements. That's something it didn't do?
I've been trying to use this code (below) from Esri. But, it's not working due to the fact, I think, that the mxd it's referencing is missing the pictures (our file directory was recently changed, so the picture path is broken). It runs with no errror and 1st_District_B3.mxd is saved in the folder, but no changes are made.
<SPAN class="keyword token">import</SPAN> arcpy mxd <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>MapDocument<SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">'R:\AtlasMaps\ATLAS_MAPS_17\New folder\1st_District_B2.mxd'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> elm <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ListLayoutElements<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"GRAPHIC_ELEMENT"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"*logo*"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">if</SPAN> elm<SPAN class="punctuation token">.</SPAN>name <SPAN class="operator token">==</SPAN> <SPAN class="string token">'County-logo-1x1Small'</SPAN><SPAN class="punctuation token">:</SPAN> elm<SPAN class="punctuation token">.</SPAN>sourceImage <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'P:\Images\County-logo.JPG'</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">'{} changed'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>elm<SPAN class="punctuation token">.</SPAN>sourceImage<SPAN class="punctuation token">)</SPAN> mxd<SPAN class="punctuation token">.</SPAN>saveACopy<SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">'R:\AtlasMaps\ATLAS_MAPS_17\New folder\1st_District_B3.mxd'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">del</SPAN> mxd<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Below's a printscn of the document with the broken picture element source. It's giving you the path where the JPEG once lived. It's now in the P:\Images folder.
Are you aware of a way to list and repair broken source picture elements?
Thanks in advance.
This addin/toolbar (for ArcCatalog) is still in my final developement.....but I'm getting close to getting my addin that will do several things, including listing all your broken links, and then give the option to update. I'll attache the documentation, which is all over the place as far as instructions, and the addin, which has been tested in 10.3.x (but should work in 10.2). Instruction for loading (from an email I sent to test staff earlier this morning)
Save the ChkandFixLinks.esriaddin file to anywhere handy. Double click, it will ask if you want to install…click Install Add-in.
Then open or reopen ArcCatalog. If you don’t see the toolbar, or not sure, go to Customize (on top menu bar)
Click on that and you will see Toolbars> …hover to the right and make sure the toolbar is checked. If you don’t see it, click it off/on until you see where it is.
Click on the third icon over (for the one that will give a unique list of all broken links in a folder)
In the dialog box, use the folder icon and then navigate to the folder where all you mxd’s are located (it will go thru (walk) all the subfolders underneath too) and leave the other two as they are
Then click ok, and it will run. When completed, it will have created a couple files…they are the same, just one is and Excel file, and the other is comma delimited….I suggest opening the Excel (.xls) file to review. They will be called BrokenSrc with the date/time it was run.
Sorry this is pretty messy....when it's completed with the additional scripts, I will post (probably to ArcScripts 2.0). The 4th icon over will do a bulk change from drive->drive or drive->UNC look at the Samples folder (if you unzip the esriaddin ("after installing) and there is a samples folder for format. After the bulk updates, it will run a new unique list. The next script which is almost complete, will allow for changing longer paths, shapes or coverages to FGDB, etc. Feedback is welcome and appreciated (especially if it doesn't work at all for you). BTW - the first three tools don't change anything, just create lists/reports so you can see what you need to fix....i.e. other than createing .txt, .xls, and .csv files (all with unique name_date_time for file name, they can not do any damage (but you must have write access to the folder you are analyzing. (although setting the path might work (haven't tested).
I hope these tools help.
Hey Kevin.
I was just curious if either of these answers worked for you. I am about to be in the same boat, with somewhere near a thousand MXD's. I'm going to have to put something together over the next couple of days.
Thanks Kevin.
-Josh
import os,fnmatch,arcpy def find(pattern, path=os.getcwd()): for path, dirs, files in os.walk(path): for filename in files: if fnmatch.fnmatch(filename, pattern):yield os.path.abspath(os.path.join(path, filename)) for f in find('*.mxd', 'C:/Data'): mxd = arcpy.mapping.MapDocument(f) mxd.findAndReplaceWorkspacePaths(r"oldfilepath1", r"newfilepath1") mxd.findAndReplaceWorkspacePaths(r"oldfilepath2", r"newfilepath2") mxd.save()
import arcpy, os path = os.getcwd() # or path = r"C:\Documents" for fileName in os.listdir(path): fullPath = os.path.join(path, fileName) if os.path.isfile(fullPath): basename, extension = os.path.splitext(fullPath) if extension == '.mxd': mxd = arcpy.mapping.MapDocument(fullPath) mxd.findAndReplaceWorkspacePaths(r"oldfilepath1", r"newfilepath1") mxd.findAndReplaceWorkspacePaths(r"oldfilepath2", r"newfilepath2") mxd.save() del mxd
Hi folks,As our research group has run out of space on a network drive, our IT department just moved all of our folders/data to a new network drive. However, in doing this all of the folder structures for the data locations have changed. As a result, none of our project files (e.g., .mxd) are functioning. As we have ~150-200 .mxd project files does anyone know if there is a piece of code which can automatically work through all of the ArcGIS related folders and find and replace the mapped network drive info or the folder structure.I found this piece of code, but this only works for a single file. What I would like to be able to do is a batch process to look through all folders/subfolders/files and find and replace the workspace path (Note: we are working with ArcGIS 10.1). import arcpymxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")mxd.findAndReplaceWorkspacePaths(r"C:\Project\Data", r"D:\Project\Data")mxd.saveACopy(r"D:\Project\Project.mxd")del mxdThanks.
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.