Python Noob

1289
19
11-23-2011 04:31 PM
JoshMoloney
New Contributor
Greetings,

I am an amatuer when it comes to python so could someone please help with my simple questions:

1) Is the arcpy module available in ArcGIS 9.3 (I think it is 10 / python 2.6)
2) What is the python code to open a shapefile in ArcGIS 9.3 (not using arcpy module)?

Thanks,
Josh
Tags (2)
0 Kudos
19 Replies
DanPatterson_Retired
MVP Emeritus
1  No, arcpy is for version 10
2  check the 9.3 help files for "searchcursor"
0 Kudos
JoshMoloney
New Contributor
Hi Dan,

I checked out the searchcursor... not sure how you use this to open a shapefile up in ArcMap. I have used cursors before in VBA code to go through each record.

I call the python script from a toolbox within an open session of ArcMap. I want it to open a shapefile (chosen by the user with a dialog box). I can get the filepath to the script with the dialog box but I have no idea how to add that shapefile to the arcmap session.. It is easy with arcpy, but I don't have that luxury.

Any ideas?

Thanks,
Josh
0 Kudos
DanPatterson_Retired
MVP Emeritus
makefeaturelayer ?  Is that what you are after?
0 Kudos
JamesHood
Occasional Contributor
Greetings,

I am an amatuer when it comes to python so could someone please help with my simple questions:

1) Is the arcpy module available in ArcGIS 9.3 (I think it is 10 / python 2.6)
2) What is the python code to open a shapefile in ArcGIS 9.3 (not using arcpy module)?

Thanks,
Josh



How about this?

shapefile = "c://temp//shapefile.shp"

That's a joke, kind of.
What exactly are you trying to do ?  What do you mean by open?  Why can't the user add a shapefile to ArcMap and then open its attribute table or what ever it wants to do there?

What's the desired process or end result?  What does the user need to do with the shapefile once its been opened?
0 Kudos
PatrickFischer1
New Contributor III
ok I was in your shoes not two months ago. First off there a few things you need to understand with python firstly being how geoprocessing works from python to arcgis. A lot of useinfo is in the help menu about python, main points to learn first are parameters, workspaces, and the tools in the tool box. You can also view the script of any tool by putting inside of a model (model builder) and export that model to a script. You can then view that script and look at how the tool is written. You can also look up a tool through the help menu and read its documentaion which will tell you what parameters do what. I hope this helps you hit the ground running. In regard to your question use the yellow Add Data button to add shapefiles to your mxd.
0 Kudos
JoshMoloney
New Contributor
Greetings Folks,

Sorry for being too vague guys!

The shapefile is created during the script (which I created using model builder then adding a few tweaks). It works fine, I have no problems with this basic scripting. All I want to do is open a shapefile that gets created during the script. At the moment the shapefile is created and after the script has run the user has to press the yellow add data button. I think this is inefficient and would like the shapefile to automatically open.

Does anyone know how to open a shapefile in ArcMap using python???
0 Kudos
MathewCoyle
Frequent Contributor
So you mean you want to add a shapefile to your TOC? I think people were confused because opening and adding a shapefile mean two different things to most people.

What you want is
arcpy.MakeFeatureLayer_management(yourShapefile, "TOC name")
arcpy.RefreshActiveView()
0 Kudos
JoshMoloney
New Contributor
Thats right, however I can't use arcpy (don't have arcpy module with arcgis 9.3)
0 Kudos
MathewCoyle
Frequent Contributor
Doesn't matter, it is a basic tool available in any recent python package. You just use your arcgisscripting instance instead of arcpy.
http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?id=1867&pid=1865&topicname=Make_Feature_Layer_(D...
0 Kudos