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.

EDIT: Here's my full script and hopefully a better way of explaining what I need done:

#Import

import arcpy, sys, os

# Set environment settings

arcpy.env.workspace = sys.argv[1]  
inFiles = sys.argv[2]  
outWorkspace = sys.argv[3]  
projectGDB = sys.argv[4]+".gdb"  
coordinate = sys.argv[5]  
clipBoundary = sys.argv[6]  
scratchGDB = sys.argv[7]+".gdb"  

# CREATE A GEODATABASE

arcpy.CreateFileGDB_management(outWorkspace, projectGDB) # Here I create the database
# for the projected files to go into  
arcpy.CreateFileGDB_management(outWorkspace, scratchGDB)  

# CHANGE THE PROJECTION

arcpy.BatchProject_management(inFiles, outWorkspace+"\\"+gdbName, coordinate)

# CLIP FEATURES TO STUDY AREA BUFFER

fcs = arcpy.ListFeatureClasses() # Here I need it to somehow read from the GDB with 
# my projected files in it that was created above..however it reads from the workspace 
# and because the workspace is set before running the script I can not choose the GDB 
# because it is not created yet

for fc in fcs:  
    arcpy.Clip_analysis(fc, clipBoundary, outWorkspace+"\\"+scratchGDB+"\\"+fc+"__clipped")

I am wondering if there is a way to change the workspace as you move through the python script without having to do something like wrap tkinter around it.

For example:
I have set up my inital workspace through the parameters (sys.argv) so that I can create a gdb to store my files - this is a general "Project" folder as my workspace
Next I have a batch project in which the files that the user wants to be projected are chosen, the output of these projected files is to the geodatabse that was created NEXT (and here's where my issue comes in) I need to clip my projected features to a boundary of the study area, so I have a batch clip written out:

fcs = arcpy.ListFeatureClasses()
for fc in fcs:
     arcpy.Clip_analysis(fc, clipBoundary, outWorkspace+"\\"+gdbName+"\\"+fc+"__clipped")

However to select the fc from fcs I need it to be looking into the projected files GDB to read all the feature classes...however if I just run the script from the beginning to this point the workspace is still sitting in my main project folder and therefore there are no feature classes that will be read into the script........

share|improve this question
1  
Hi and welcome to GIS.se. I'm having a really hard time following you, so can you edit your post to describe in complete and clear sentences what the script is supposed to do, what the arguments/parameters are, and the desired outputs? The complete script with comments would also be helpful. Also please be sure to indent any code sections with 4 spaces as described in the Markdown Editing Help so that code indentation, which is part of Python's syntax, is preserved and readability is improved. Please also avoid using HTML tags in your posts. –  blah238 Mar 24 '12 at 23:34
2  
I agree with blah238, your question could be clearer, but from the sounds of it tkinter is not needed. Changing workspaces is probably best done using arcpy.env.workspace –  PolyGeo Mar 25 '12 at 7:34
    
Could this be done using ListDatasets? –  InsaneBunny Mar 31 '12 at 0:02
1  
Congratulations for solving your own problem, and many thanks for taking the time to report back on your solution! An alternate solution might have been to move arcpy.env.workspace = sys.argv[1] from line 7 to line 20, after the GDBs are created. –  matt wilkie Apr 12 '12 at 19:40
add comment

1 Answer 1

up vote 3 down vote accepted

I finally figured it out! I added the ListWorkspaces command which on its own did not work but I found that I required add in the arcpy.env.workspace = workspace command in order to switch the workspace I was looking in to search throught the feature classes within it.

workspaces = arcpy.ListWorkspaces("script*", "FileGDB")
for workspace in workspaces:
arcpy.AddMessage(workspaces)
arcpy.env.workspace = workspace 
fcs = arcpy.ListFeatureClasses()
# For every feature within the feature class, clip to the boundary specified by the user
for fc in fcs:
    arcpy.AddMessage(fc)
    arcpy.Clip_analysis(fc, clipBoundary, outWorkspace+"\\"+scratchGDB+\\"+fc+"__clipped")
share|improve this answer
    
Go ahead & mark your own answer as accepted, since it may help future readers. –  RyanDalton Apr 12 '12 at 17:23
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.