How to change output directory?

3324
3
03-26-2015 10:34 AM
alexbullen
New Contributor II

So I've got this great, simple loop running thanks to a member here. I set the workspace, pass in the array of files to be processed, run my tool, and append a descriptor to the filename. However this is all done in the same workspace. Is there a way to change the output directory to a different location while keeping my input workspace? The script is below.

import arcpy

from arcpy import env

#where we're working

env.workspace = r"D:\Broomfield.Lidar\HARN_Vertices.gdb"

#array of files to be processed

fc = ['D:\\Broomfield.Lidar\\HARN_Vertices.gdb\\VertexN2W187North', 'D:\\Broomfield.Lidar\\HARN_Vertices.gdb\\VertexN2W188', 'D:\\Broomfield.Lidar\\HARN_Vertices.gdb\\VertexN3E180', 'D:\\Broomfield.Lidar\\HARN_Vertices.gdb\\VertexN3E190', 'D:\\Broomfield.Lidar\\HARN_Vertices.gdb\\VertexN3E191']

vertices = arcpy.ListFeatureClasses()

print vertices

for fc in vertices:

    arcpy.MinimumBoundingGeometry_management(fc, fc + "_Poly", "RECTANGLE_BY_AREA", "ALL", "", "NO_MBG_FIELDS")

Tags (2)
0 Kudos
3 Replies
DanPatterson_Retired
MVP Emeritus

get the list of files first, then set the workspace...I am confused as to why you set the environment, then provide a list o files which I presume are in your gdb, then process the files.

0 Kudos
DarrenWiens2
MVP Honored Contributor

The way it is now, you've listed some feature classes in the variable 'fc', listed some feature classes in your workspace into the variable 'vertices', destroyed the 'fc' list, and are looping through everything in 'vertices' in a new variable called 'fc'.

I think you may want:

import arcpy, os

#array of files to be processed
fcs = ['D:\\Broomfield.Lidar\\HARN_Vertices.gdb\\VertexN2W187North', 'D:\\Broomfield.Lidar\\HARN_Vertices.gdb\\VertexN2W188', 'D:\\Broomfield.Lidar\\HARN_Vertices.gdb\\VertexN3E180', 'D:\\Broomfield.Lidar\\HARN_Vertices.gdb\\VertexN3E190', 'D:\\Broomfield.Lidar\\HARN_Vertices.gdb\\VertexN3E191']

outputFolder = r'C:\junk' # or whatever you choose

for fc in fcs:
     fcName = os.path.basename(fc) # returns 'VertexN2W187North', etc.
    arcpy.MinimumBoundingGeometry_management(fcName, os.path.join(outputFolder, fcName + "_Poly"), "RECTANGLE_BY_AREA", "ALL", "", "NO_MBG_FIELDS")
0 Kudos
alexbullen
New Contributor II

I'll give these os.path functions a try - still pretty new to scripting as you can probably tell. My odd setup comes changing from using a simple ListFeatureClasses (to get all the features) to only wanting certain features to be processed, hence the array. From there I just messed with the variables until the script worked, haha.

0 Kudos