Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I have a Python script for ArcGIS that makes a new feature class. I can add this to ArcGIS as a new Script (without parameters), however the resulting feature class is not automatically added to the map layers. How does this happen? Here is an example of my Python script:

import os
import arcgisscripting

out_feat_class = 'out.shp'
workspace = r'C:\temp'

gp = arcgisscripting.create(9.3)
gp.toolbox = 'management'
gp.workspace = workspace

# Create feature class
gp.CreateFeatureclass(workspace, out_feat_class, 'POINT')

# Add a field to it
gp.AddField(out_feat_class, 'Value', 'DOUBLE')

# Get insert cursor
rows = gp.InsertCursor(out_feat_class)
feat = rows.NewRow()

# Set attribute data
feat.SetValue('Value', 123.45)

# Set geometry
ptObj = gp.CreateObject('Point')
ptObj.x = 101.224
ptObj.y = 442.440
feat.Shape = ptObj

# Add to feature class

# Done, clean up
del ptObj, feat, rows

There are no errors, a feature class is made, but it does not automatically appear in the map. I'm using ArcGIS 10.0, but I'd like this to be backwards compatible with ArcGIS 9.3.

share|improve this question

marked as duplicate by blah238, Aragon, iant, Simon, Devdatta Tengshe Feb 7 '13 at 11:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 3 down vote accepted

On your script tool parameters definitions, create a derived, output parameter and set it using SetParameterAsText in your script.

This still depends on the Add results of geoprocessing operations to the display setting under Geoprocessing-Geoprocessing Options being checked, however.


(ignore the ModelBuilder part)

See also:

share|improve this answer
This is working well with ArcGIS 10.0, but I'm having difficulties testing this with ArcGIS 9.3. There are no error messages with SetParameterAsText, and the derived result does not make it back to the map. Any ideas? – Mike T Feb 7 '13 at 4:26
Sorry, I don't have a 9.3 machine to test with, so no. It should work on that version with this method, though. – blah238 Feb 7 '13 at 4:29
Perhaps 9.3 requires a Feature Layer type parameter and MakeFeatureLayer_management instead of a Feature Class. Something you can try anyways. – blah238 Feb 7 '13 at 4:30
True, this solution works for 9.3. I found the registry setting on this ArcGIS 9.3 test computer: HKEY_CURRENT_USER\Software\ESRI\ArcToolbox\Settings\AddOutputsToDisplay was set to 0 and not 1. – Mike T Feb 7 '13 at 5:12
That checkbox should also be present in 9.3:… – blah238 Feb 7 '13 at 5:15

Try this:

tempLayer = "layer"
# Make a layer from the feature class
addLayer = arcpy.mapping.Layer(tempLayer)
arcpy.mapping.AddLayer(df, addLayer, "AUTO_ARRANGE")
share|improve this answer
This will not work on 9.3. – blah238 Feb 7 '13 at 4:11
Actually I use 10.0 and it worked for me. So I posted. I am sorry then – Emi Feb 7 '13 at 4:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.