ionarawilson

Add layer works for a dataframe but not the other

Discussion created by ionarawilson on Sep 4, 2013
Latest reply on Sep 5, 2013 by ionarawilson
I am creating a tool that the user can use to clip polygons to soils. So he first starts editing, draws a polygon, clicks the tool, choose the soil file to be used for the clipping, then runs the tool. After the clip layer is created, I want it to be added to the data frame, but no matter what I try, it does not get added to the active dataframe. I tested the script adding the clipped polygon to another dataframe and it works fine. How is it not being added to the first dataframe? Both have the same coordiante system. Could it be because the dataframe is in edit mode? Thanks

    def execute(self, parameters, messages):
        """The source code of the tool."""
       
        arcpy.env.workspace = "D:/ArcGISData/SARS/Temp"


        Soils =  parameters[0].valueAsText
       
        df = arcpy.mapping.ListDataFrames(arcpy.mapping.MapDocument('CURRENT'))[0]
        dfspatialref =  df.spatialReference
        arcpy.env.outputCoordinateSystem = dfspatialref
        clippedsoils = "ClippedSoils"
        if arcpy.Exists(clippedsoils):
            arcpy.Delete_management(clippedsoils)       
        output = arcpy.Clip_analysis(Soils, "Stewardship",clippedsoils)[0]
        outputlyr = arcpy.mapping.Layer("D:/ArcGISData/SARS/Temp/ClippedSoils.shp")

        arcpy.mapping.AddLayer(df, outputlyr, "AUTO_ARRANGE")
        df2 = arcpy.mapping.ListDataFrames(arcpy.mapping.MapDocument('CURRENT'))[1]
    
        arcpy.mapping.AddLayer(df2, outputlyr, "AUTO_ARRANGE")
        
        arcpy.AddWarning("Completed clipping of soils.")

        
        return

Outcomes