I want to clip a layer from data frame 1 and add it to the data frame 2 using the following script. But instead it just add all grids to current data frame 1 and don't update data frame 2. Please suggest how to stop it from updating data frame 1 TOC and add new layer to data frame 2.

import arcpy 
import pythonaddins

class DrawRectangle(object):
"""Implementation for rectangle_addin.tool (Tool)"""
    def __init__(self):
        self.enabled = True
        self.cursor = 1
        self.shape = 'Rectangle'

    def onRectangle(self, rectangle_geometry):
        mxd = arcpy.mapping.MapDocument(r'C:/test.mxd')
        df1 = arcpy.mapping.ListDataFrames(mxd, "View1")[0]
        df2 = arcpy.mapping.ListDataFrames(mxd, "View2")[0]
        extent = rectangle_geometry
                              "%f %f %f %f" % (extent.XMin, extent.YMin, extent.XMax, extent.YMax), "oras", "#", "#", "NONE")
        grid1 = arcpy.MakeRasterLayer_management("oras", "grid2", "#", "", "")
        arcpy.SaveToLayerFile_management(grid1, 'grid2.lyr')
        grid3 = arcpy.mapping.Layer('grid2.lyr')

I don't know about all the funny business you are attempting with different layer and variable names but one thing you will definitely want to try is setting arcpy.env.addOutputsToMap to False to prevent intermediate outputs being added to the map.

| improve this answer | |
  • Intermediate outputs are now under control. The funny business :) is basically about inserting the output from one dataframe to another because extents of both frames are different. It is supposed to be simple add layer thing, but not working. – Ibe Feb 14 '13 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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