I have asked similar question at stackoverflow but posting here as well since it involves ArcGIS and python Add-In. Following code shows first step where i have to declare output folder as global so that later outputs can be saved in it as well. Right now I am getting an error at output folder string r'optfile/ras1'. Any help how to correctly store files in output folder and declare it as global would be appreciative.
import arcpy
import os
import pythonaddins
from datetime import datetime
now = datetime.now()
month = now.month
year = now.year
optfile = "C:/temp/"+str(year)+"_"+str(month)
class DrawRectangle(object):
"""Implementation for rectangle_addin.tool (Tool)"""
def __init__(self):
self.enabled = True
self.cursor = 1
self.shape = 'Rectangle'
os.makedirs(optfile)
def onRectangle(self, rectangle_geometry):
"""Occurs when the rectangle is drawn and the mouse button is released.
The rectangle is a extent object."""
extent = rectangle_geometry
arcpy.Clip_management(r'D:/test',
"%f %f %f %f" % (extent.XMin, extent.YMin, extent.XMax, extent.YMax),
r'optfile/ras1', "#", "#", "NONE")
arcpy.RefreshActiveView()
