Can arc9.3 read arcpy scripts/toolboxes made on arc 10

1215
7
09-22-2010 12:18 PM
MikeHouts
New Contributor
Some of our workstations have been upgraded to 10, while others are still at 9.3.  Im trying to share a model/toolbox I made using 10 with a user still on 9.3 (python 2.5).  I  saved the toolbox as a 9.3 toolbox, but it contained some python script that references arcpy.  Will a simple update to python 2.6 enable it to recognize the arcpy call, or is everything created in 10 stuck there. 

Thanks
0 Kudos
7 Replies
JeffBarrette
Esri Regular Contributor
ArcGIS 9.3 applications can NOT read the ArcPy site package newly available at 10 so import arcpy is not understood by 9.3.

You can replace import arcpy with import arcgisscripting - both 9.3 and 10 can use that.  This will work if you are only using capabilities available at 9.3.  There are some new functions that won't be backwards compatible (e.g,  all of arcpy.mapping).
0 Kudos
MikeHouts
New Contributor
Thanks,

I will try replacing the arcpy calls.  Below is the code I am trying to run.  It is a series of "select by attributes" to narrow down to a single polygon, then a zoom to selected.  Pretty sure this is all available in 9.3, right?



# Import arcpy module
import arcpy

# set workspace
arcpy.env.workspace = "C:/temp/"

mxd = arcpy.mapping.MapDocument('CURRENT')
df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]

# Script arguments
section = arcpy.GetParameterAsText(0)
township = arcpy.GetParameterAsText(1)
range_ = arcpy.GetParameterAsText(2)
range_dir = arcpy.GetParameterAsText(3)

# Local variables:
PLSS = "PLSS"

#### Use the SelectLayerByAttribute tool to select a Section
arcpy.SelectLayerByAttribute_management(PLSS, "NEW_SELECTION", "\"SECTION\" = "+section)
arcpy.SelectLayerByAttribute_management(PLSS, "SUBSET_SELECTION", "\"TOWNSHIP\" = "+township)
arcpy.SelectLayerByAttribute_management(PLSS, "SUBSET_SELECTION", "\"RANGE\" = "+range_)
arcpy.SelectLayerByAttribute_management(PLSS, "SUBSET_SELECTION", "\"RANGE_dir\" = "+range_dir)

# zoom to the selection
df.zoomToSelectedFeatures()
df.scale = df.scale * 2.0

# Clear the selection and refresh the active view
arcpy.SelectLayerByAttribute_management(PLSS, "CLEAR_SELECTION")
arcpy.RefreshActiveView()
0 Kudos
MikeHouts
New Contributor
Update...

I got the select portion of the code to work fine by replacing the arcpy calls, but cant find a way to set the data frame to the selected feature. 

I did find some long convoluted method that looped through all the polygons and created an envelope, but this cant be the only way.

Any suggestions on doing a zoom to selected in 9.3

Thanks
0 Kudos
JeffBarrette
Esri Regular Contributor
Unfortuneately you won't be able to.  Arcpy.mapping is a new module at 10 and is not backward compatible.

Jeff
0 Kudos
MikeHouts
New Contributor
Jeff,

Thanks to you previous post about the non backward compatibility of arcpy, I adjusted the model to get the "select by attribute" portion working, but am still stuck on the zoom to selected part.  Below is the new script, is there a way to set the data frame to the selected in 9.3?  The problem part of my script is the bottom 5 lines that are currently commented out. 

Thanks.


import sys, string, os, arcgisscripting

## create the geoprocessor object ##
gp = arcgisscripting.create()

## Load required toolboxes ##
# gp.addtoolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx        

# set workspace
# arcpy.env.workspace = "C:/temp/"

# mxd = MapDocument('CURRENT')
# df = ListDataFrames(mxd,"Layers")[0]

# Script arguments
section = gp.GetParameterAsText(0)
township = gp.GetParameterAsText(1)
range_ = gp.GetParameterAsText(2)
range_dir = gp.GetParameterAsText(3)

# Local variables:
PLSS = "PLSS"

#### Use the SelectLayerByAttribute tool to select a Section
gp.SelectLayerByAttribute_management(PLSS, "NEW_SELECTION", "\"SECTION\" = "+section)
gp.SelectLayerByAttribute_management(PLSS, "SUBSET_SELECTION", "\"TOWNSHIP\" = "+township)
# arcpy.SelectLayerByAttribute_management(PLSS, "SUBSET_SELECTION", "\"TOWNSHIP_D\" = S")
gp.SelectLayerByAttribute_management(PLSS, "SUBSET_SELECTION", "\"RANGE\" = "+range_)
gp.SelectLayerByAttribute_management(PLSS, "SUBSET_SELECTION", "\"RANGE_dir\" = "+range_dir)

##################

### zoom to the selection ###
# df.zoomToSelectedFeatures()
# df.scale = df.scale * 2.0

### Clear the selection and refresh the active view
# gp.SelectLayerByAttribute_management(PLSS, "CLEAR_SELECTION")
gp.RefreshActiveView()
0 Kudos
jamesmanzione
New Contributor
I understand that arcpy cannot be run with 9.3 applications, but can it run with Python 2.5 instead of 2.6?
0 Kudos
JeffBarrette
Esri Regular Contributor
0 Kudos