justgis

adding processed shapefiles to ArcMap automatically

Discussion created by justgis on Dec 23, 2010
Latest reply on Jan 18, 2011 by wei_ler
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!

Outcomes