<?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: Compress Project Script for Arc10 in Mapping Questions</title>
    <link>https://community.esri.com/t5/mapping-questions/compress-project-script-for-arc10/m-p/356405#M3855</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes, the purpose of the script was to reduce file sizes when you close a project but I have since discovered that the "ArcGIS Document Defragmenter" does the same job.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It would still be useful to know if you can call the "ArcGIS Document Defragmenter" from a script then I could set it to run when ArcMap closes. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Paul.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 17 Nov 2010 06:25:56 GMT</pubDate>
    <dc:creator>PaulWittle</dc:creator>
    <dc:date>2010-11-17T06:25:56Z</dc:date>
    <item>
      <title>Compress Project Script for Arc10</title>
      <link>https://community.esri.com/t5/mapping-questions/compress-project-script-for-arc10/m-p/356401#M3851</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can anybody correct the following Python script so that it will run? The basic idea is simple, it saves a copy, deletes the original, renames the copy to the original name and then opens the new (smaller) project file. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;try:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Imports&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; import arcpy, os&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Definitions&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument("CURRENT")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #file_path = os.path.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; file_path = os.path.dirname(mxd)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; file_temp = os.path.basename(Input).rstrip(os.path.splitext(Input)[1])&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; file_name = file_path + file_temp&amp;nbsp; ".mxd"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; file_name_temp = file_path + file_temp + "_Copy.mxd"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Save a copy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.saveACopy(file_name_temp)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; close(mxd)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; os.rename(file_name_temp, file_name)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; open(file_name)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Output Errors Report&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;except Exception as e:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print e.message&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # If using this code within a script tool, AddError can be used to return messages &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #&amp;nbsp;&amp;nbsp; back to a script tool.&amp;nbsp; If not, AddError will have no effect.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddError(e.message)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, it currently doesn't work and python doesn't seem to allow step by step debugging. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Oct 2010 10:00:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/compress-project-script-for-arc10/m-p/356401#M3851</guid>
      <dc:creator>PaulWittle</dc:creator>
      <dc:date>2010-10-20T10:00:18Z</dc:date>
    </item>
    <item>
      <title>Re: Compress Project Script for Arc10</title>
      <link>https://community.esri.com/t5/mapping-questions/compress-project-script-for-arc10/m-p/356402#M3852</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello Paul,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Have you tried testing your lines of code in the Python Window of ArcMap?&amp;nbsp; Here you would see immediate feedback with the code you are testing.&amp;nbsp; For example.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;filePath = os.path.dirname(mxd) throws a "Map Document object is not subscriptable".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Perhaps an alternative would be to use filePath = os.path.dirname(mxd.filePath)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm also a little concerned with trying attempting to close the application that is currently open.&amp;nbsp; After doing a little pthon searching, it appears you would need to call other modules to actually close an application (e.g., the win32com module).&amp;nbsp; This would be much easier if you were not using "current".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;os.startfile(mxd.path) is a way to open the resulting mxd.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope this helps a little,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Oct 2010 13:59:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/compress-project-script-for-arc10/m-p/356402#M3852</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2010-10-21T13:59:48Z</dc:date>
    </item>
    <item>
      <title>Re: Compress Project Script for Arc10</title>
      <link>https://community.esri.com/t5/mapping-questions/compress-project-script-for-arc10/m-p/356403#M3853</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for that, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've now got the whole script working except for the close file line... As you say, this is not an easy fix it seems. I've put my new script below, any suggestions?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;--------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Imports&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy, os, win32api&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Definitions&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd = arcpy.mapping.MapDocument("CURRENT")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#file_path = os.path.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;filePath = os.path.dirname(mxd.filePath) + "\\"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#getting the file name&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fullfile = mxd.filepath&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;file_temp = os.path.basename(fullfile)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;file_temp = file_temp.rstrip(os.path.splitext(file_temp)[1])&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Put together the full file references&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;file_name = filePath + file_temp + ".mxd"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;file_name_temp = filePath + file_temp + "_Copy.mxd"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Save a copy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd.saveACopy(file_name_temp)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#Closing the file doesn't work!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#Need to close the file to rename the copy and then open it again&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;os.rename(file_name_temp, file_name)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;os.startfile(file_name)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;--------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Many thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Paul&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Oct 2010 14:27:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/compress-project-script-for-arc10/m-p/356403#M3853</guid>
      <dc:creator>PaulWittle</dc:creator>
      <dc:date>2010-10-25T14:27:11Z</dc:date>
    </item>
    <item>
      <title>Re: Compress Project Script for Arc10</title>
      <link>https://community.esri.com/t5/mapping-questions/compress-project-script-for-arc10/m-p/356404#M3854</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;All- I'd like to know what this script does or what its application is meant to do.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I need to decrease the size of my mxd's and am wondering if this script does that.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does this script reduce file sizes of .mxd's??&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Aaron&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Nov 2010 17:05:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/compress-project-script-for-arc10/m-p/356404#M3854</guid>
      <dc:creator>AaronPaul</dc:creator>
      <dc:date>2010-11-16T17:05:57Z</dc:date>
    </item>
    <item>
      <title>Re: Compress Project Script for Arc10</title>
      <link>https://community.esri.com/t5/mapping-questions/compress-project-script-for-arc10/m-p/356405#M3855</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes, the purpose of the script was to reduce file sizes when you close a project but I have since discovered that the "ArcGIS Document Defragmenter" does the same job.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It would still be useful to know if you can call the "ArcGIS Document Defragmenter" from a script then I could set it to run when ArcMap closes. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Paul.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Nov 2010 06:25:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/compress-project-script-for-arc10/m-p/356405#M3855</guid>
      <dc:creator>PaulWittle</dc:creator>
      <dc:date>2010-11-17T06:25:56Z</dc:date>
    </item>
    <item>
      <title>Re: Compress Project Script for Arc10</title>
      <link>https://community.esri.com/t5/mapping-questions/compress-project-script-for-arc10/m-p/356406#M3856</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I was unaware of the Document Defragger or the MXD Doctor. Thank you for providing this information. I have many MXD's that are dying for this solution. Good times&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Nov 2010 20:31:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/compress-project-script-for-arc10/m-p/356406#M3856</guid>
      <dc:creator>AaronPaul</dc:creator>
      <dc:date>2010-11-17T20:31:35Z</dc:date>
    </item>
  </channel>
</rss>

