Select to view content in your preferred language

Converting scripts to arcpy for use in ags 10

3602
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
check the online help, specifically
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z0000000n000000.htm
case-sensitive
you can import arcpy and do a help(arcpy) or dir(arcpy) to get further information or import its submodules and get further info there.
0 Kudos
KevinGooss
Regular Contributor
That is helpful, thanks for that link.
For others running into this same conversion process it would be great if esri had a white paper or guide to the conversion process. But we can start one here:

1. replace 'import arcgisscripting' with 'import arcpy'
2. remove gp = arcgisscripting.create(9.3)
3. find and replace all 'gp.' with 'arcpy.'
4. modify environment vars like 'gp.extent' to read 'arcpy.env.extent'
5. check your case sensitivity for method calls like next() on a SearchCursor (not Next())

and more to follow.......
0 Kudos
ChrisMathers
Deactivated User
Two reasons why you should switch to arcpy:
1. You can use a for loop to iterate cursors in arcpy which is better than while loops.
2. arcpy.mapping lets you edit mxds programatically.

Case sensitivity is irritating though. getValue() not getvalue() or GetValue()
0 Kudos
KevinGooss
Regular Contributor
increased sensitivity to overwriting in-memory datasets
before you may have been able to get away with it but now you need to make sure you have:

arcpy.env.overwriteOutput = True
0 Kudos
KevinGooss
Regular Contributor
The very latest issue i have been dealing with is converting a script that handled some shapefile exports using the fieldMap and fieldMappings objects in arcpy.
Once again the issue was with case sensitivity. The aliasName, outputField, and name methods have to begin with lowercase as they are listed in the docs.
No errors are thrown if you have the incorrect case making it tough to track down these kinds of bugs.
My best advice is to go through the docs for each method you call and see if you have the case correctly spelled.
the next() method is used on cursors so i would check that you have the exact spelling and case syntax when creating the cursor and using it.
0 Kudos
ChrisMathers
Deactivated User
In arcpy you dont need to use next() in your cursors. Using next() was to force the cursor to advance to the next row in the table when using a while loop. Now that you can use a for loop next is not needed as for has better built in iterator functions.

for row in arcpy.SearchCursor(featureclass):
do some stuff and automatically go to the next row
0 Kudos
KimOllivier
Honored Contributor
Don't need next() ?
Yes you do, in anything but a SearchCursor because you need access to a row object.

How would you do cur.insert(row) and cur.update(row) ?

If your 9.3 script is working, why bother rewriting it?

The arcgisscripting module is still there and it works just fine.
Maybe write new scripts using arcpy, and leave the rest alone.
0 Kudos
JasonScheirer
Esri Alum
You do not need to do anything to make your scripts work in 10.0, all previous functionality with the geoprocessor object will continue to work unmodified.
0 Kudos
KevinHibma
Esri Regular Contributor
I don't think that is entirely true.  There have been lots of my models and scripts that seem to have trouble.


Could you post something from a previous version which doesn't work in 10?
0 Kudos