adding processed shapefiles to ArcMap automatically

1020
5
12-23-2010 06:59 AM
denisedavis
Occasional Contributor III
When I run an arcpy script in ArcGIS10 to perform analysis on a shapefile, the shapefile is added to the map automatically. I can't find a way to make this happen in 9.3. I've looked for code corresponding to the "add data" button and can't seem to find anything. I've tried the addLayer but it doesn't seem to work right with a shapefile (although, I could be doing something wrong).

# Import system modules
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")
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Analysis Tools.tbx")


# Local variables...
shapefile_name = "shapefile_name"
selected_shp = gp.GetParameterAsText(0)
Output_Feature_Class = gp.GetParameterAsText(1)

# Process: Select...
gp.Select_analysis(shapefile_name, selected_shp, "")

# Process: Dissolve...
gp.Dissolve_management(selected_shp, Output_Feature_Class, "", "", "MULTI_PART", "DISSOLVE_LINES")

# Process: Add the shapefile to the map
gp.AddFeatureLayer(selected_shp,Output_Feature_Class)

Thanks for any help!
Tags (2)
0 Kudos
5 Replies
MikeHunter
Occasional Contributor
You can try gp.AddOUtputsToMap=True.  That works with a arcgisscripting gp object, but not with arcpy.  But with arcpy, you can simply write the code to add layers with arcpy.mapping. 

Also, there is a switch in the geoprocessing options to automatically add gp results to the display. 

Mike
0 Kudos
denisedavis
Occasional Contributor III
Thanks for the input. I'm not able to try it right now, however as soon as I'm able to give it a shot, I will.
0 Kudos
karinweixler
New Contributor II
Hello,

have you tried the AddLayer function of arcpy.mapping? If so, does it work in your code? Because i tried to and i am getting errors.
With the Python Scirpt i create a FeatureClass in a FileGeodatabase and would like to add the created FeatureClass into my map.

Karin
0 Kudos
ChrisMathers
Occasional Contributor III
You have to create an layer object before you can add it to the map with addLayer. yourLayer=arcpy.Layer('path')
0 Kudos
karinweixler
New Contributor II
Thanks for the hint! That solved the problem.
0 Kudos