I'm using
sys.stdout.write( "." )
in a a loop to print a series of dots when it has processed an .mxd that didn't fit the criteria that I am working on (if it fits criteria, then it lists the path). It's just a very simple "progress bar" for my tool.
This works fine in a python window, but I'm not sure how to do this in a tool, without getting a bunch of newlines that come with a print or arcpy.AddMessage (which looks messy...but I could live with it)
I've read ab out many of the progress bar approaches, but this one line (or equivalent) is what I'm hoping for. I'll include a snippet of the code..
<SPAN class="comment token"># ... snippet....will not run as standalone as is</SPAN>
updateServices <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN>
update <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">False</SPAN>
myMsgs<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"\nFinding STARTED services accesing {0} to STOP\n Dots represent services that are OK"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>updateDS<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> startedService <SPAN class="keyword token">in</SPAN> myServices<SPAN class="punctuation token">:</SPAN>
mxdFound <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">False</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="operator token">not</SPAN> update<SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># will print a dot for services or df within mxd that are ok, using for progress status</SPAN>
sys<SPAN class="punctuation token">.</SPAN>stdout<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN> <SPAN class="string token">"."</SPAN> <SPAN class="punctuation token">)</SPAN>
update <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">False</SPAN>
<SPAN class="comment token">#myMsgs("Reviewing service: {0}".format(startedService))</SPAN>
theServicePath <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>servicesDir<SPAN class="punctuation token">,</SPAN> startedService<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="operator token">not</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Exists<SPAN class="punctuation token">(</SPAN>theServicePath<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
myMsgs<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"...we have a problem"</SPAN><SPAN class="punctuation token">)</SPAN>
exit
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="comment token"># myMsgs(" {0}".format(startedService)) # Can use if want to list all services</SPAN>
<SPAN class="keyword token">for</SPAN> root<SPAN class="punctuation token">,</SPAN> dirs<SPAN class="punctuation token">,</SPAN> files <SPAN class="keyword token">in</SPAN> os<SPAN class="punctuation token">.</SPAN>walk<SPAN class="punctuation token">(</SPAN>theServicePath<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> fn <SPAN class="keyword token">in</SPAN> files<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>root<SPAN class="punctuation token">,</SPAN> fn<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>fn<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="operator token">not</SPAN> extension <SPAN class="operator token">==</SPAN> <SPAN class="string token">".mxd"</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">pass</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="comment token">#myMsgs(" mxd file found")</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">try</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="comment token"># Do stuff with MXD using arcpy.mapping </SPAN>
<SPAN class="keyword token">for</SPAN> df <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ListDataFrames<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
lyrList <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ListLayers<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">)</SPAN>
mxdFound <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
<SPAN class="keyword token">for</SPAN> lyr <SPAN class="keyword token">in</SPAN> lyrList<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> lyr<SPAN class="punctuation token">.</SPAN>isFeatureLayer <SPAN class="operator token">and</SPAN> update <SPAN class="operator token">==</SPAN> <SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> lyr<SPAN class="punctuation token">.</SPAN>supports<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"dataSource"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">and</SPAN> update <SPAN class="operator token">==</SPAN> <SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">:</SPAN>
theSource <SPAN class="operator token">=</SPAN> lyr<SPAN class="punctuation token">.</SPAN>dataSource
<SPAN class="keyword token">if</SPAN> updateDS<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">in</SPAN> theSource<SPAN class="punctuation token">:</SPAN>
update <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
myMsgs<SPAN class="punctuation token">(</SPAN><SPAN class="string token">" {0} is using {1}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>startedService<SPAN class="punctuation token">,</SPAN> updateDS<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
updateServices<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>startedService<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">break</SPAN>
<SPAN class="keyword token">except</SPAN> AttributeError<SPAN class="punctuation token">:</SPAN>
myMsgs<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"\n !!! WARNING: {0} has unreadable dataframes(s),\n will stop as precaution...\n"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>basename<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">.</SPAN>filePath<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
updateServices<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>startedService<SPAN class="punctuation token">)</SPAN>
update <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
<SPAN class="keyword token">pass</SPAN>
<SPAN class="keyword token">del</SPAN> mxd
<SPAN class="comment token"># ...</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></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>Line #8 is where the line is that works in the python window.
Thanks.