I have a script that runs IDW iterations and I'd like for the files to be automatically added to the map display after they are produced and contain the default symbology that ArcMap generates when you run the tool.

I'm not sure how complicated that is, but I hope it's possible.

Note: I am a novice at scripting.

My script:

# Import arcpy module
import arcpy
from arcpy import env
from arcpy.sa import *

# Check out any necessary licenses

# Allows overwrite of files
arcpy.env.overwriteOutput = True

inPointFeatures = arcpy.GetParameterAsText(0)

fieldList = arcpy.GetParameterAsText(1)

# IDW - Define local variables
cellSize = 250.0
power = 2
searchRadius = RadiusVariable(12)

for fieldName in fieldList.split(';'):

    # Iterate IDW
    outIDW = Idw(inPointFeatures, fieldName, cellSize, power, searchRadius)
    # Save the output 

1 Answer 1


This following code works for me, though it might be messy. Note: This code only works for me when using ArcMap v10.0 and v10.1. There's also an issue when adding raster layers to a map (using MakeRasterLayer instead of MakeFeatureLayer). It adds the map to the display properly, but it is sourced to a temporary location rather than the workspace folder.

    # Convert shapefile to layer
    out_layer = "shapefile.lyr"
    display_layer = "shapefile.lyr"
    co_layer = fieldName + "shapefile.lyr"
    arcpy.MakeFeatureLayer_management(Output_Feature_Class, out_layer)
    arcpy.SaveToLayerFile_management(out_layer, display_layer, "ABSOLUTE")

    # Adjust symbology of layer
    arcpy.ApplySymbologyFromLayer_management(display_layer, symbology)
    arcpy.SaveToLayerFile_management(display_layer, co_layer, "ABSOLUTE")

    # Add layer to map
    mxd = arcpy.mapping.MapDocument("CURRENT")
    df = arcpy.mapping.ListDataFrames(mxd, "*")[0]
    addLayer = arcpy.mapping.Layer(co_layer)
    arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")
    del mxd, df, addLayer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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