<?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 Re: Create blank MXD from python? in Mapping Questions</title>
    <link>https://community.esri.com/t5/mapping-questions/create-blank-mxd-from-python/m-p/329217#M3482</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Old thread, but I just used your code although I had to change 'r' to 'w+' in third line. Is this due to changes in python since 2014? I don't understand how your code could work&amp;nbsp;because with the open function in 'read' mode it could not create the file.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 26 Jun 2019 23:46:19 GMT</pubDate>
    <dc:creator>EnvironmentalIntelligence</dc:creator>
    <dc:date>2019-06-26T23:46:19Z</dc:date>
    <item>
      <title>Create blank MXD from python?</title>
      <link>https://community.esri.com/t5/mapping-questions/create-blank-mxd-from-python/m-p/329206#M3471</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I was looking through the new ArcPy functions, and I didn't see a function or Toolbox tool to just create a new blank MXD from scratch.&amp;nbsp; Does something like this exist?&amp;nbsp; Seems like a great function to have as a starting point for map manipulation.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Mar 2010 21:46:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/create-blank-mxd-from-python/m-p/329206#M3471</guid>
      <dc:creator>AndrewRudin</dc:creator>
      <dc:date>2010-03-26T21:46:53Z</dc:date>
    </item>
    <item>
      <title>Create blank MXD from python?</title>
      <link>https://community.esri.com/t5/mapping-questions/create-blank-mxd-from-python/m-p/329207#M3472</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The workflow for this is to use an already saved blank MXD on the filesystem, open it, and use MapDoc.saveAs to have a new, blank map document to work with.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 27 Mar 2010 18:44:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/create-blank-mxd-from-python/m-p/329207#M3472</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2010-03-27T18:44:30Z</dc:date>
    </item>
    <item>
      <title>Create blank MXD from python?</title>
      <link>https://community.esri.com/t5/mapping-questions/create-blank-mxd-from-python/m-p/329208#M3473</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the solution.&amp;nbsp; I thought of that as well, but to me that sounds more like a workaround.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If that's the way to do it, then great.&amp;nbsp; Just seemed like a gap in the functionality and wanted to bring it up.&amp;nbsp; There are lots of functions and tools for modifying and packaging up MXD's, but no way to create a blank one to start manipulating from the beginning... using code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Mar 2010 15:11:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/create-blank-mxd-from-python/m-p/329208#M3473</guid>
      <dc:creator>AndrewRudin</dc:creator>
      <dc:date>2010-03-29T15:11:41Z</dc:date>
    </item>
    <item>
      <title>Create blank MXD from python?</title>
      <link>https://community.esri.com/t5/mapping-questions/create-blank-mxd-from-python/m-p/329209#M3474</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Not so much a workaround as much as a conscious decision: the default legal-sized page layout with full-page map frames makes sense in a Desktop environment, but it is not the most appropriate layout or page size to be used across the board. The onus is on the author of the map scripts of the decision of map layout template to be used -- this may seem like an inconvenience on the surface, but we anticipate it will result in much higher quality maps in automation than if a default were forced on users as it integrates the design of the map document's layout into the thought process of providing map automation services to end users of the services.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Mar 2010 06:07:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/create-blank-mxd-from-python/m-p/329209#M3474</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2010-03-31T06:07:54Z</dc:date>
    </item>
    <item>
      <title>Create blank MXD from python?</title>
      <link>https://community.esri.com/t5/mapping-questions/create-blank-mxd-from-python/m-p/329210#M3475</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;While I can understand the desire for this, I'm not sure why you would want to use Python to&amp;nbsp; open a blank mxd when you can just as easily fire up a brand new ArcMap session through your operating system.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Mar 2010 12:18:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/create-blank-mxd-from-python/m-p/329210#M3475</guid>
      <dc:creator>JoshWhite</dc:creator>
      <dc:date>2010-03-31T12:18:20Z</dc:date>
    </item>
    <item>
      <title>Create blank MXD from python?</title>
      <link>https://community.esri.com/t5/mapping-questions/create-blank-mxd-from-python/m-p/329211#M3476</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You can always use the templates in the system as a starting point as well.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;starting_point = arcpy.mapping.MapDocument(os.path.join(arcpy.GetInstallInfo()['InstallDir'], 'bin', 'Templates', 'LetterLandscape.mxt'))&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Mar 2010 15:56:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/create-blank-mxd-from-python/m-p/329211#M3476</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2010-03-31T15:56:22Z</dc:date>
    </item>
    <item>
      <title>Create blank MXD from python?</title>
      <link>https://community.esri.com/t5/mapping-questions/create-blank-mxd-from-python/m-p/329212#M3477</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the responses.&amp;nbsp; I guess I was taking the angle of creating something like the old ArcInfo Workstation ArcEditor AML equivelant of opening arcmap, in which you basically chose which layers you wanted and their symbology in the script and your map was created 'on the fly' every time.&amp;nbsp; This way I can manage the SDE login and version components of the layers dynamically for every user in the script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;At my office we use individual SDE logins for each user, and we have several servers, so creating MXD's with passwords stripped out of layers gets pretty annoying for end users.&amp;nbsp; And operating system authentication is apparantly out of the question according to our DBA's.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm sure I'll figure something out.... if I ever do this.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Apr 2010 13:18:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/create-blank-mxd-from-python/m-p/329212#M3477</guid>
      <dc:creator>AndrewRudin</dc:creator>
      <dc:date>2010-04-08T13:18:39Z</dc:date>
    </item>
    <item>
      <title>blank mxd with FGDB raster layer and .lyr symbology</title>
      <link>https://community.esri.com/t5/mapping-questions/create-blank-mxd-from-python/m-p/329213#M3478</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Not so much a workaround as much as a conscious decision...&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;similiar issue - I need to be able to generate (from python) an mxd containing a FGDB raster layer symbolized with a standard .lyr file.&amp;nbsp;&amp;nbsp; I need to do this dozens or hundreds of times with different rasters symbolized identically.&amp;nbsp; Needs to be a data view (not layout) with an extent zoomed to the raster.&amp;nbsp;&amp;nbsp; All of the gp. functions up to this point work great - I can maneuver the data into perfect shape - but I can't see the elegant way to 1) open/create mxd 2) add FGDB raster layer 3) import .lyr and&amp;nbsp; 4) save from python.&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be enormously appreciated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Apr 2010 19:56:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/create-blank-mxd-from-python/m-p/329213#M3478</guid>
      <dc:creator>RichardSutton</dc:creator>
      <dc:date>2010-04-26T19:56:09Z</dc:date>
    </item>
    <item>
      <title>Create blank MXD from python?</title>
      <link>https://community.esri.com/t5/mapping-questions/create-blank-mxd-from-python/m-p/329214#M3479</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;So something like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import os

arcpy.env.workspace = r"c:\data\file.gdb"
my_mxd = arcpy.mapping.MapDocument(r"c:\path\to\my.mxd")
data_frame = arcpy.mapping.ListDataFrames(my_mxd)[0]
# Switch to data view
my_mxd.activeView = data_frame.name
# Load standard layer with symbology, append to TOC in first data frame
my_layer = arcpy.mapping.Layer(r"c:\path\to\some.lyr")
arcpy.mapping.AddLayer(data_frame, my_layer, 'TOP')
# Loop through rasters in workspace, swap out layer's source with raster's
for fcname in arcpy.ListRasters():
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Full path to raster
&amp;nbsp;&amp;nbsp;&amp;nbsp; new_raster = os.path.join(arcpy.env.workspace, fcname)
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Set layer's source
&amp;nbsp;&amp;nbsp;&amp;nbsp; my_layer.dataSource = new_raster
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Zoom to extent
&amp;nbsp;&amp;nbsp;&amp;nbsp; df.extent = arcpy.Describe(new_raster).extent
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Save to disk
&amp;nbsp;&amp;nbsp;&amp;nbsp; my_mxd.saveACopy("c:\\output\\out_%s.mxd" % fcname)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:35:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/create-blank-mxd-from-python/m-p/329214#M3479</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2021-12-11T15:35:36Z</dc:date>
    </item>
    <item>
      <title>Re: Beta 10: Create blank MXD from python?</title>
      <link>https://community.esri.com/t5/mapping-questions/create-blank-mxd-from-python/m-p/329215#M3480</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thx for the example. I just needed to change 1 line:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt; my_layer.dataSource = new_raster
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;to&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
my_layer.replaceDataSource(arcpy.env.workspace, 'RASTER_WORKSPACE', fcname[:-4])
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Kind Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Rainer&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:35:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/create-blank-mxd-from-python/m-p/329215#M3480</guid>
      <dc:creator>R_Spitzer</dc:creator>
      <dc:date>2021-12-11T15:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: Create blank MXD from python?</title>
      <link>https://community.esri.com/t5/mapping-questions/create-blank-mxd-from-python/m-p/329216#M3481</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;old thread but i thought&amp;nbsp; i would post my answer as it does not require an existing map doc&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;this does assume that you have arcMap installed and not just arcpy. but who is using arcpy w/o having ArcMap installed?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;map_file = r'c:\test\test_map..mxd'&lt;/P&gt;&lt;P&gt;# open and close a file&lt;/P&gt;&lt;P&gt;open(map_file,'r').close()&lt;/P&gt;&lt;P&gt;# open the file with default application&lt;/P&gt;&lt;P&gt;os.startfile(map_file)&lt;/P&gt;&lt;P&gt;# sleep for a couple minutes to allow the file to be fully opened&lt;/P&gt;&lt;P&gt;time.sleep(120)&lt;/P&gt;&lt;P&gt;# kill the application in a pretty violent way yet not corrupting the file.&lt;/P&gt;&lt;P&gt;os.system("taskkill /im arcmap.exe /f")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# work with yout map&lt;/P&gt;&lt;P&gt;mxd = arcpy.mapping.MapDocument(map_file)&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Oct 2014 22:47:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/create-blank-mxd-from-python/m-p/329216#M3481</guid>
      <dc:creator>DanielSmith</dc:creator>
      <dc:date>2014-10-24T22:47:23Z</dc:date>
    </item>
    <item>
      <title>Re: Create blank MXD from python?</title>
      <link>https://community.esri.com/t5/mapping-questions/create-blank-mxd-from-python/m-p/329217#M3482</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Old thread, but I just used your code although I had to change 'r' to 'w+' in third line. Is this due to changes in python since 2014? I don't understand how your code could work&amp;nbsp;because with the open function in 'read' mode it could not create the file.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Jun 2019 23:46:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/create-blank-mxd-from-python/m-p/329217#M3482</guid>
      <dc:creator>EnvironmentalIntelligence</dc:creator>
      <dc:date>2019-06-26T23:46:19Z</dc:date>
    </item>
  </channel>
</rss>

