|
POST
|
Chris: Why do I need to worry about the number of subprocesses? I wrote my main python script to loop through a directory, its subdirectories and files looking for mxds. Then I call the subprocess python script for the file that has focus and I manipulate that mxd. Once that is done and the mxd gets saved, I thought the code goes back to the main python script and releases the subprocess python script from memory. Then I loop to the next mxd and call the subprocess python script again. The reason I went this route in the first place was due to memory usage always climbing while looping through a directory until the python script just hung. Could it be that I just needed to release additional items from temporary memory when I was just using one script to obtain the results? Thanks.
... View more
02-07-2012
01:26 PM
|
0
|
0
|
1042
|
|
POST
|
Thanks Chris That was the syntax that was needed to call the subprocess python script in Windows. I could not find any other examples of that syntax when searching the web.
... View more
02-07-2012
11:33 AM
|
0
|
0
|
1042
|
|
POST
|
Chris: Here's the code I am trying to run to call a subprocess to actually modify properties of mxd files:
import os, sys, string, arcpy
import subprocess
mxd_match = ".mxd"
fileErrList = []
procs = []
Directory_Search = r"\\tgapparc00\e$\restore5\Planning_Run\Broken_Links\Test"
for root, dirs, files in os.walk(Directory_Search):
fListLength = len(files)
if (fListLength != 0):
n = 0
for f in files:
if f.endswith(mxd_match):
full_path = root + "\\" + str(f)
cmd = "'C:\Python26\ArcGIS10.0\python.exe \\\\tgapparc01\\c$\\ReplaceSource.py' full_path"
proc = subprocess.Popen(cmd,shell=True)
procs.append(proc)
... View more
02-07-2012
10:39 AM
|
0
|
0
|
3090
|
|
POST
|
Chris: I did see your last response and I moved the python script, that is called, to a folder with no spaces. No matter how I format the cmd line, the subprocess never gets executed.
... View more
02-07-2012
10:29 AM
|
0
|
0
|
3090
|
|
POST
|
Chris: Can you please be a little bit more specific in what your code is looking for with the cmd = "python foo.py arg1 arg2" line? I still cannot get my code to evaluate the subprocess python script. Does python refer to python.exe that has been installed on the computer that you are running this script from (e.g. c:\Python26\ArcGIS10.0\python.exe)? Does foo.py refer tp the python script that you are running in the subprocess? If so, wouldn't you need to specify the full path to this file? Are arg1 and arg2 variables from the primary script that you are sending to the subprocess script? If so, what is the syntax to get the subprocess script to accept these arguments? I ask because I am using arcpy.GetParameterAsText(0) to evaluate the single argument that I am trying to pass. Your assistance is greatly appreciated. Thanks.
... View more
02-07-2012
10:03 AM
|
0
|
0
|
3090
|
|
POST
|
I believe as long as the new connection that you created in ArcCatalog has the direct connection parameters specified, the source should then be changed to a direct connection.
... View more
02-07-2012
09:56 AM
|
0
|
0
|
892
|
|
POST
|
Chris: I tried running the first portion of your code, but the subprocess is not executing. Here is my syntax to call the subprocess script: cmd = "C:\\Python26\\ArcGIS10.0\\python.exe \\\\tgapparc01\\c$\\GIS Testing\\ReplaceSource.py full_path" In the cmd line, full_path is the file that has the focus. File is stored in the full_path variable. In the ReplaceSource.py script, I am trying to use the arcpy.GetParameterAsText(0) to bring in this argument. I'm not sure if this is the problem? Could this issue possibly be how I am calling out the python executable and the python script that gets run in the subprocess? Your assistance is greatly appreciated. Thanks.
... View more
02-07-2012
08:29 AM
|
0
|
0
|
3090
|
|
POST
|
Brittney: Have you thought of trying to use the replaceDataSource method to solve this problem? I'm thinking you could create the new direct connect database connections in ArcCatalog that would correspond to your existing database connections. Then in your code, get each feature class in your mxd that originate from this database and replace the old connection with the new direct connection. Use the Validate = TRUE property so only those existing connections that you have created a corresponding direct connection for will be resourced (if set to FALSE, you will get broken links if the connection strings have not been already created in ArcCatalog). I hope this helps.
... View more
02-07-2012
06:37 AM
|
0
|
0
|
892
|
|
POST
|
Here is the link to setup a script tool where you can add a parameter to the script as as input: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Adding_a_script_tool/00150000001r000000/ I followed this ESRI Help myself and I was able to setup a tool that would walk through all the subdirectories in a user selected directory.
... View more
02-07-2012
06:20 AM
|
0
|
0
|
1453
|
|
POST
|
Have you thought about trying root = arcpy.GetParameterAsText(0) where you are passing this as a value that the user can navigate to if you set it up as a directory in an ArcToolbox script? This is how I am able to achieve what you want to do in your script.
... View more
02-07-2012
06:08 AM
|
0
|
0
|
1453
|
|
POST
|
To All Python Users: I have a script that is updating mxds and then saving them. After saving the mxd I am deleting the mxd object, but memory usage keeps increasing until the python script just hangs. I have read that I can use a subprocess to fix this problem, but I am unsure of the syntax to use. I will be drilling down through a directory and all of its subdirectories for mxd files (This will be my main python script). Once I have an mxd file as the focus, I want to use a subprocess to start another python script that will open the mxd, replace data sources, save the mxd and then delete the mxd object from memory. Then I will return to the main script to get another file which should free up memory as the subprocess has terminated. Does anyone know the syntax I would use to call the secondary python script with an argument being the mxd file that has the focus? Any help or hints are greatly appreciated. Thank you.
... View more
02-07-2012
04:40 AM
|
0
|
17
|
7408
|
|
POST
|
Thanks Jake. Do you have any idea why I need to employ this more complicated workaround than your original simpler code?
... View more
02-03-2012
09:51 AM
|
0
|
0
|
251
|
|
POST
|
Jake: Do you think it might matter how the SDE connection is broken? I created a new SDE version owned by myself off the default version. I added data from SDE with this version to an mxd and saved the mxd. I then deleted the SDE version in ArcCatalog which breaks the link. I then ran my python script on this mxd with the broken SDE link.
... View more
02-03-2012
09:03 AM
|
0
|
0
|
1438
|
|
POST
|
Jake: As requested, here is my code that returns different results from your code: import os, arcpy, sys
from arcpy import env
env.overwriteOutput = True
mxd_match = ".mxd"
for root, dirs, files in os.walk(arcpy.GetParameterAsText(0)):
fListLength = len(files)
if (fListLength != 0):
n = 0
for f in files:
if f.endswith(mxd_match):
full_path = root + "\\" + str(f)
try:
mxd = arcpy.mapping.MapDocument(full_path)
broken = arcpy.mapping.ListBrokenDataSources(mxd)
for n in broken:
for lyr in arcpy.mapping.ListLayers(mxd, n):
arcpy.AddMessage("The broken SDE layer dataSource is " + lyr.dataSource)
del mxd
except:
print arcpy.GetMessages(2)
... View more
02-03-2012
08:07 AM
|
0
|
0
|
1438
|
|
POST
|
Jake: I modifed my code slightly to duplicate your code and I am still receiving dataSource property for an SDE feature class was \'feature class dataset name.feature class name' (e.g. ADMIN_BOUNDARIES.MUNIS) instead of something like Database Connections\SDEConnection.sde\vector.VECTOR.ap for an SDE broken link. I was able to get the dataSource property in your format if I called this property from an SDE feature class that was not broken, so I'm guessing that the dataSource property works differently if the SDE connection is broken. Should I place a call with ESRI Technical Support for further assistance with this issue? Thanks.
... View more
02-03-2012
07:34 AM
|
0
|
0
|
1438
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 4 weeks ago | |
| 1 | 09-26-2025 06:10 AM | |
| 1 | 09-04-2025 02:19 PM | |
| 1 | 08-29-2025 08:29 AM | |
| 1 | 08-21-2025 12:45 PM |
| Online Status |
Online
|
| Date Last Visited |
Thursday
|