<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Bing Authorization interrupts arcpy script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/bing-authorization-interrupts-arcpy-script/m-p/133729#M10438</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I made this happy little arcpy script to fix some data source problems:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;print "Hi, I will fix find and replace file path sections on your behalf. \nGive me a moment to just count the number of MXDs I'll be looking at for you today..."&lt;/P&gt;&lt;P&gt;import os&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;mxdfiles = [os.path.join(d, x)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for d, dirs, files in os.walk(r"PATH")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for x in files if x.endswith(".mxd")]&lt;/P&gt;&lt;P&gt;print "\nOk, I'll be working through "+str(len(mxdfiles))+" MXDs. \nStarting this process now..."&lt;/P&gt;&lt;P&gt;for item in mxdfiles:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "\nWorking on: "+item&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(item)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.findAndReplaceWorkspacePaths(r"PATH OLD1", r"PATH NEW")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.findAndReplaceWorkspacePaths(r"PATH OLD2", r"PATH NEW")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.findAndReplaceWorkspacePaths(r"PATH OLD3", r"PATH NEW")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.findAndReplaceWorkspacePaths(r"PATH OLD4", r"PATH NEW") &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.findAndReplaceWorkspacePaths(r"PATH OLD5", r"PATH NEW2")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.save()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; del mxd&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Completed "+str(mxdfiles.index(item)+1)+" maps so far."&lt;/P&gt;&lt;P&gt;print "\nProcess complete!" &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Unfortunately, though, when it comes across a MXD with a Bing imagery layer, up pops a Bing Authorization box which you have to click 'OK' on (hitting Enter works, too). This is because my company no longer has a license to use Bing/Microsoft Virtual Earth, so this little box comes up every time a MXD is opened manually, or, it seems, when one is invoked by my script. This means I have to either:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Find a way to programmatically click that button or ignore it.&lt;/P&gt;&lt;P&gt;2. Leave a coffee mug on my Enter key overnight.&lt;/P&gt;&lt;P&gt;3. Remove the Bing (or Microsoft Virtual Earth*) layers programmatically.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I Googled to no avail regarding option 1. Before going for option 2, I tried option 3. As a test, I used the following script to try removing Microsoft Virtual Earth* layers (their group is Microsoft Virtual Earth, inside that there are three layers with the same name plus Hybrid, Aerial or Roads suffixed):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;mxd = arcpy.mapping.MapDocument(r"PATH.mxd")&lt;/P&gt;&lt;P&gt;for df in arcpy.mapping.ListDataFrames(mxd):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd, "Microsoft Virtual Earth", df):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.RemoveLayer(df, lyr)&lt;/P&gt;&lt;P&gt;mxd.saveACopy(r"PATH2.mxd")&lt;/P&gt;&lt;P&gt;del mxd &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It ran without errors, including without the Bing Authorization dialog box popping up. The resulting MXD, however, would not open without crashing. I therefore used this script to retrieve its list of layers:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;mxd = arcpy.mapping.MapDocument(r"PATH2.mxd")&lt;/P&gt;&lt;P&gt;df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]&lt;/P&gt;&lt;P&gt;print arcpy.mapping.ListLayers(mxd, "", df)&lt;/P&gt;&lt;P&gt;del mxd&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;...and found that the Microsoft Virtual Earth* layers had in fact been removed. Btw, the list layers script also did not cause the Bing Authorization box to pop up. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Before I try to incorporate my script to remove these layers into the one I'm working on to walk through all MXDs and fix their paths, I need to know:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. What is causing the Bing Authorisation dialog box to pop up with my initial script, but not the layer deletion nor listing ones? &lt;/P&gt;&lt;P&gt;2. Why after running the Bing/Microsoft Virtual Earth layer deletion script the MXD is now corrupted and causes ArcMap to crash (crash report box comes up)?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 12 Aug 2015 12:30:16 GMT</pubDate>
    <dc:creator>wilwaters</dc:creator>
    <dc:date>2015-08-12T12:30:16Z</dc:date>
    <item>
      <title>Bing Authorization interrupts arcpy script</title>
      <link>https://community.esri.com/t5/python-questions/bing-authorization-interrupts-arcpy-script/m-p/133729#M10438</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I made this happy little arcpy script to fix some data source problems:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;print "Hi, I will fix find and replace file path sections on your behalf. \nGive me a moment to just count the number of MXDs I'll be looking at for you today..."&lt;/P&gt;&lt;P&gt;import os&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;mxdfiles = [os.path.join(d, x)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for d, dirs, files in os.walk(r"PATH")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for x in files if x.endswith(".mxd")]&lt;/P&gt;&lt;P&gt;print "\nOk, I'll be working through "+str(len(mxdfiles))+" MXDs. \nStarting this process now..."&lt;/P&gt;&lt;P&gt;for item in mxdfiles:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "\nWorking on: "+item&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(item)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.findAndReplaceWorkspacePaths(r"PATH OLD1", r"PATH NEW")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.findAndReplaceWorkspacePaths(r"PATH OLD2", r"PATH NEW")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.findAndReplaceWorkspacePaths(r"PATH OLD3", r"PATH NEW")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.findAndReplaceWorkspacePaths(r"PATH OLD4", r"PATH NEW") &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.findAndReplaceWorkspacePaths(r"PATH OLD5", r"PATH NEW2")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.save()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; del mxd&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Completed "+str(mxdfiles.index(item)+1)+" maps so far."&lt;/P&gt;&lt;P&gt;print "\nProcess complete!" &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Unfortunately, though, when it comes across a MXD with a Bing imagery layer, up pops a Bing Authorization box which you have to click 'OK' on (hitting Enter works, too). This is because my company no longer has a license to use Bing/Microsoft Virtual Earth, so this little box comes up every time a MXD is opened manually, or, it seems, when one is invoked by my script. This means I have to either:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Find a way to programmatically click that button or ignore it.&lt;/P&gt;&lt;P&gt;2. Leave a coffee mug on my Enter key overnight.&lt;/P&gt;&lt;P&gt;3. Remove the Bing (or Microsoft Virtual Earth*) layers programmatically.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I Googled to no avail regarding option 1. Before going for option 2, I tried option 3. As a test, I used the following script to try removing Microsoft Virtual Earth* layers (their group is Microsoft Virtual Earth, inside that there are three layers with the same name plus Hybrid, Aerial or Roads suffixed):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;mxd = arcpy.mapping.MapDocument(r"PATH.mxd")&lt;/P&gt;&lt;P&gt;for df in arcpy.mapping.ListDataFrames(mxd):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd, "Microsoft Virtual Earth", df):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.RemoveLayer(df, lyr)&lt;/P&gt;&lt;P&gt;mxd.saveACopy(r"PATH2.mxd")&lt;/P&gt;&lt;P&gt;del mxd &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It ran without errors, including without the Bing Authorization dialog box popping up. The resulting MXD, however, would not open without crashing. I therefore used this script to retrieve its list of layers:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;mxd = arcpy.mapping.MapDocument(r"PATH2.mxd")&lt;/P&gt;&lt;P&gt;df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]&lt;/P&gt;&lt;P&gt;print arcpy.mapping.ListLayers(mxd, "", df)&lt;/P&gt;&lt;P&gt;del mxd&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;...and found that the Microsoft Virtual Earth* layers had in fact been removed. Btw, the list layers script also did not cause the Bing Authorization box to pop up. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Before I try to incorporate my script to remove these layers into the one I'm working on to walk through all MXDs and fix their paths, I need to know:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. What is causing the Bing Authorisation dialog box to pop up with my initial script, but not the layer deletion nor listing ones? &lt;/P&gt;&lt;P&gt;2. Why after running the Bing/Microsoft Virtual Earth layer deletion script the MXD is now corrupted and causes ArcMap to crash (crash report box comes up)?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Aug 2015 12:30:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/bing-authorization-interrupts-arcpy-script/m-p/133729#M10438</guid>
      <dc:creator>wilwaters</dc:creator>
      <dc:date>2015-08-12T12:30:16Z</dc:date>
    </item>
  </channel>
</rss>

