Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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'

os.chdir(workspace)
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
rows.InsertRow(feat)

# 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

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.

2 Answers 2

up vote 2 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.

Screenshot

(ignore the ModelBuilder part)

See also:

share
    
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
1  
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: resources.esri.com/help/9.3/arcgisdesktop/com/gp_toolref/… –  blah238 Feb 7 '13 at 5:15

Try this:

tempLayer = "layer"
# Make a layer from the feature class
arcpy.MakeFeatureLayer_management("C:/data/mexico.gdb/cities",tempLayer)
addLayer = arcpy.Layer(tempLayer)
arcpy.mapping.AddLayer(df, addLayer, "AUTO_ARRANGE")
arcpy.RefreshTOC()
share
2  
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

This site is currently not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .