Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

How to save output files in a folder created within python Add-In?

$
0
0
Output folder is defined during execution of python Add-In and it is required that output should be stored in the created folder. But I am getting an error pertaining to output folder string such as "r'optfile/ras1'" which is also shown below. Any help how to correctly store output file in the created folder would be appreciative.

Code:

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()


Viewing all articles
Browse latest Browse all 2485

Latest Images

Trending Articles



Latest Images