次のコードは、後の出力も同様に保存できるように、出力フォルダーをグローバルとして宣言する必要がある最初のステップを示しています。現在、出力フォルダー文字列 r'optfile/ras1' でエラーが発生しています。ファイルを出力フォルダーに正しく保存し、それをグローバルとして宣言する方法については、助けていただければ幸いです。
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()