Hi,
I'm attempting to print lists of broken source data to a text file using the write to text function, but I'm at a loss. The code I have works up until it's meant to write to the text file.
You'll notice that the write function has nothing between the parentheses. This is because I'm not sure what to put there in order to print the list of broken layers and broken picture elements. In other words, I'm uncertain as to what variable to use for the write function. Basically, I'm trying to write the lists shown in the Interactive Window below (PrtScn) to a text file, and save the file in the workspace folder.
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">import</SPAN> os
<SPAN class="keyword token">from</SPAN> arcpy <SPAN class="keyword token">import</SPAN> env
<SPAN class="comment token"># set variables</SPAN>
path <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'\\gisfile\GISmaps\AtlasMaps\ATLAS_MAPS_17\New folder'</SPAN>
<SPAN class="comment token"># iterates through folder and lists broken layers</SPAN>
<SPAN class="keyword token">for</SPAN> fileName <SPAN class="keyword token">in</SPAN> os<SPAN class="punctuation token">.</SPAN>listdir<SPAN class="punctuation token">(</SPAN>path<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
fullPath <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>path<SPAN class="punctuation token">,</SPAN>fileName<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>isfile<SPAN class="punctuation token">(</SPAN>fullPath<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
basename<SPAN class="punctuation token">,</SPAN>extension <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>splitext<SPAN class="punctuation token">(</SPAN>fullPath<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> extension <SPAN class="operator token">==</SPAN> <SPAN class="string token">".mxd"</SPAN><SPAN class="punctuation token">:</SPAN>
mxd <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>MapDocument<SPAN class="punctuation token">(</SPAN>fullPath<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"current MXD being checked is: "</SPAN> <SPAN class="operator token">+</SPAN> fileName
<SPAN class="keyword token">for</SPAN> brknList <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ListBrokenDataSources<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"\t broken layer: "</SPAN> <SPAN class="operator token">+</SPAN> brknList<SPAN class="punctuation token">.</SPAN>name
<SPAN class="comment token"># iterates through folder and checks for broken picture element source</SPAN>
<SPAN class="keyword token">for</SPAN> elem <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">"PICTURE_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">print</SPAN> <SPAN class="string token">"\t broken picture element name: "</SPAN> <SPAN class="operator token">+</SPAN> elem<SPAN class="punctuation token">.</SPAN>name
<SPAN class="comment token"># Write to text file</SPAN>
txtFile <SPAN class="operator token">=</SPAN> open<SPAN class="punctuation token">(</SPAN>path <SPAN class="operator token">+</SPAN> <SPAN class="string token">"{}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"BrkSrceLst.txt"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"w"</SPAN><SPAN class="punctuation token">)</SPAN>
txtFile<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"MXDs that have broken source data"</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"\n"</SPAN><SPAN class="punctuation token">)</SPAN>
txtFile<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"----------------------------------------------"</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"\n"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> f <SPAN class="keyword token">in</SPAN> fullPath<SPAN class="punctuation token">:</SPAN>
f<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> ename <SPAN class="keyword token">in</SPAN> elem<SPAN class="punctuation token">.</SPAN>name<SPAN class="punctuation token">:</SPAN>
ename<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
txtFile<SPAN class="punctuation token">.</SPAN>close<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"\t completed"</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Thanks in advance for any help!