You are here: > ESRI Forums > arcgis desktop discussion forums > Thread Replies

ArcGIS Desktop Discussion Forums

ArcGIS Desktop - Geoprocessing ArcToolbox forum

Python script runs from the command line no...   Ralph Dell Mar 15, 2007
Re: Python script runs from the command lin...   Corey Tucker Mar 15, 2007
Re: Python script runs from the command lin...   Ralph Dell Mar 16, 2007
Re: Python script runs from the command lin...   Philippe Le Grand Mar 16, 2007
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Python script runs from the command line not from ArcToolBox 
Author Ralph Dell 
Date Mar 15, 2007 
Message There are some similar threads from the last few years hopefully this will add useful information to the discussion. In ArcGis 9.2 with the version of python from the install cd I was having problems with script(s) that would run from the command line but fail when running from ArcToolBox.

Here is a simple sample that is copying a personal geodatabase feature class to another feature class in the same geodatabase.

# copy2.py

import sys, string, os, arcgisscripting

gp = arcgisscripting.create()

gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")

output = "C:\\geodb\\geodb.mdb\\junk"
input = "C:\\geodb\\geodb.mdb\\T373020"

try:
gp.CopyFeatures_management(input, output, "", "0", "0", "0")
except:
x = 0
while x < gp.MessageCount:
gp.AddReturnMessage(x)
x = x + 1

print gp.GetMessages()

The while loop in the except allowed me to see a message similar to this.

Executing: CopyFeatures input output FILL90 0 0 0
Failed to execute parameters are not valid.

Of course the parameters are not valid. In the script I passed nothing for the config keyword value and the geoprocessor picked up the FILL90 from my Environment Settings, Geodatabase Settings, Output Config Keyword.
It was news to me that the geoprocessor would inset values where none were intended. I tried a variety of parameters from the python script and a config value was always inserted. Does anyone have a suggestion of a parameter/value I could use in the python script so it would work correctly from ArcToolBox?
Or is the lesson "Do Not Use Environment Settings" if you are using python scripts for geoprocessing because the geoprocessor will arbitrarily insert values. That would seem to leave users in a situation where a script will work on one desktop but not another because of the absence or lack of environment settings on that desktop.





 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Python script runs from the command line not from ArcToolBox 
Author Corey Tucker 
Date Mar 15, 2007 
Message Ralph,

The behavior you are seeing is actually intended. The Copy Features tool has an optional configuration keyword parameter, which you only see if you expand the ArcSDE settings option on the tool dialog. When the tool is used from a desktop application, such as ArcMap, teh default value of this parameter is set to the configuration keyword in the environment settings. This behavior is not seen from a standalone script, as there is no parent application with an environment.

Within the script, expressly set the configuration setting to nothing so that any value passed from the application is not used when a tool is run within the script, as below, or make sure the setting is not set in the calling appllication.

try:
gp.CopyFeatures_management(input, output, "", "0", "0", "0")
# Reset the config keyword to nothing
gp.configkeyword = ""
except: =

Corey Tucker
ESRI 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Python script runs from the command line not from ArcToolBox 
Author Ralph Dell 
Date Mar 16, 2007 
Message The answer you provided solved the problem.
gp.configkeyword = ""
gp.CopyFeatures_management(input, output, "", "0", "0", "0")

In my opinion the intended behaviour is a poor design decision by esri for the following reasons. If I pass a value to a tool from a script I expect that is the value that the tool will use. Without the gp.configword statement the the script will run on one desktop where there are no config environment settings and fail on another where there are config environment settings. Rereading the usage tips I see that the Config Keyword effects this tool but it was not obvious to me the full implications of that statement.
I work in an environment where tools are shared on multiple desktops and the environment settings can be diffrent on each one consequently I will start using the statement gp.configkeyword = "" in all my scripts so I can have confidence in there behaviour.
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Python script runs from the command line not from ArcToolBox 
Author Philippe Le Grand 
Date Mar 16, 2007 
Message Ralph,

I would second your opinion, and add the following comment:
CONFIGKeyword does not appear prominently enough in the documentation, along with all of the issues related to environment settings. Furthermore, the documentation entry on CONFIGKeyword in the desktop help does not even mention that the empty string "" is a valid value; this should be remedied.

Philippe