Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9197329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:02:52+00:00 2026-06-17T22:02:52+00:00

Following code shows first step where i have to declare output folder as global

  • 0

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()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:02:54+00:00Added an answer on June 17, 2026 at 10:02 pm

    I think you mean that the value r'optfile/ras1' doesn’t use your optfile variable. That’s because Python does not magically read your mind and replace parts of strings that happen to match a variable name.

    You have to use the optfile variable explicitly, by concatenating it with the /ras1 part:

        arcpy.Clip_management(
            r'D:/test',
            "%f %f %f %f" %(extent.XMin, extent.YMin, extent.XMax, extent.YMax),
            optfile + '/ras1', "#", "#", "NONE")
    

    or, better yet, use the os.path.join() function to take care of the path separators for you:

    import os.path
    
    # ...
    
        arcpy.Clip_management(
            r'D:/test',
            "%f %f %f %f" %(extent.XMin, extent.YMin, extent.XMax, extent.YMax),
            os.path.join(optfile, 'ras1'), "#", "#", "NONE")
    

    Note that your problem has nothing to do with global variables; this applies to wherever your variable that you want to concatenate comes from.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the following code, the first log statement shows a decimal as expected, but
The following code shows a button that allows you to select a file (should
The following code shows what I currently have. It is an adapter for circular
The following code with alternating background I have shows up fine in Chrome and
I have the following code. The first attempt at binding to click event does
Following code shows the problem: Advancing a full year from the first day of
The following code shows 1 view, 1 partial view, and 1 controller . The
Currently, the following code shows a blank line if Address2 (which comes from the
Consider the following code which shows compile time error : #include <stdio.h> int main(int
In the following code every time button is clicked the alter shows the value

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.