Select to view content in your preferred language

Converting scripts to arcpy for use in ags 10

3551
15
12-14-2010 12:14 PM
KevinGooss
Regular Contributor
Is anyone else out there undergoing a conversion project to get python scripts written for 9.3 to work in 10?
I'm wondering if there is a guide to the common things that need to be changed? If it is absolutely necessary to upgrade to arcpy and what kinds of experiences people have had doing this?
I am trying to convert about 30 scripts and it's a big job. Besides the find and replace with gp to arcpy I'm finding alot of case sensitive issues like SearchCursors next() method which cannot be Next() like it used to.
Right now I'm stuck on

result1 = arcpy.GetCount_management("TempSelection")
    affectedFeatures = int(result1.GetOutput(0))


the GetOutput call produces an error and I'm trying to work around it.
Any suggestions?
Tags (2)
0 Kudos
15 Replies
DanPatterson_Retired
MVP Emeritus
Kevin, perhaps the transfer from 9.2 to 10 is causing more of a problem (aka the switch from enumerations to python lists etc).  The only thing that I can think of off hand is that 9.3 had an ARCGISHOME environment variable which no longer exists in 10.  i used it frequently to import toolboxes that may reside there along with the system toolboxes, however, unless an alias was established, the method in V10 is a little more circuitous...
...code before
  sub_folder = "ArcToolbox/Toolboxes/"
  install_dir = arcpy.GetInstallInfo()['InstallDir'].replace("\\","/")
  tbx_home = os.path.join(install_dir, sub_folder)
...code after

unless I have missed something obvious
0 Kudos
GavinMcGhie
Regular Contributor
So far, I have also needed to change the path to any toolboxes I've loaded. For example...
from:
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")
to:
gp.AddToolbox("C:\Program Files\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Data Management Tools.tbx")

Am I doing something I don't need to? This was originally a script back at 9.1 or 9.2 that imported win32com.client. Do we no longer need to call out a specific toolbox?
Thanks, Gavin
0 Kudos
RDHarles
Regular Contributor
To my knowledge, you never needed to add the "AddToolbox" line to a script as long as you included the toolbox name after the tool name [e.g. gp.Clip_analysis()].  Before Arc10, adding the toolbox to the tool name was optional, now it's required.
0 Kudos
GavinMcGhie
Regular Contributor
Hmm. Odd. I assume that must have come out of model builder at some point as that is how we originally started our scripting. I've always assumed it was needed. I'll test without thanks.
G
0 Kudos
RDHarles
Regular Contributor
Hmm. Odd. I assume that must have come out of model builder at some point as that is how we originally started our scripting. I've always assumed it was needed. I'll test without thanks.
G


You're not alone.  I see it all the time in people's scripts, output from Model Builder and even in ESRI's documention (before 9.3/10.0).
0 Kudos
curtvprice
MVP Esteemed Contributor
So far, I have also needed to change the path to any toolboxes I've loaded. For example...
from:
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")
to:
gp.AddToolbox("C:\Program Files\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Data Management Tools.tbx")

Am I doing something I don't need to? This was originally a script back at 9.1 or 9.2 that imported win32com.client. Do we no longer need to call out a specific toolbox?
Thanks, Gavin


If youre still using GP:

import os
ARCHOME = gp.ArcInstallInfo("Desktop")["InstallDir"] # replaces os.environ["ARCHOME"] at 9.3
gp.AddToolbox(os.path.join(ARCHOME,"ArcToolbox/Toolboxes/Data Management Tools.tbx")

The above code will work for 9.x or 10.x

But, note that system toolboxes do NOT need to be added, a new gp automatically has them all available, even though an export from modelbuilder includes the AddToolbox call.
0 Kudos