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.

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
        arcpy.Clip_management(r"data/iras",
                              "%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')
        arcpy.mapping.AddLayer(df2,grid3,"TOP")
share|improve this question
add comment

1 Answer 1

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.

share|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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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