Select to view content in your preferred language

Copy Features saves output in the input directory

2458
2
Jump to solution
12-08-2014 11:59 AM
ChrisBrannin
Regular Contributor

I am trying to setup a simple batch copy features tool. I would like to have a simple tool where the user adds input features and specifies the output location.

I tested and it works like this:

import arcpy
from arcpy import env
import os

arcpy.env.overwriteOutput = True

inFC = r"M:\Destinations"
outWorkspace = r"M:\OtherLayers"


variable = "TEST"

arcpy.env.workspace = inFC


fcList = arcpy.ListFeatureClasses()


#Export the feature classes
for fc in fcList:
    print fc
    outFC = os.path.join(outWorkspace, fc + "_" + variable)
    arcpy.CopyFeatures_management(fc, outFC)

print "Finished"

When I set it up as a tool with this code:

import arcpy
from arcpy import env
import os


arcpy.env.overwriteOutput = True

inFC = arcpy.GetParameterAsText(0)
outWorkspace = arcpy.GetParameterAsText(1)

variable = arcpy.GetParameterAsText(2)


arcpy.AddMessage(inFC)
arcpy.env.workspace = inFC


fcList = arcpy.ListFeatureClasses()


#Export the feature classes
for fc in inFC.split(";"):
    outFC = os.path.join(outWorkspace, fc + "_" + variable)
    arcpy.AddMessage(outFC)
    arcpy.CopyFeatures_management(fc, outFC)

It runs but saves the copies in the input directory and ignores the outWorkspace all together. I have set the output parameters as: Datatype = folder & Direction = output.

Am I setting this up incorrectly? Is there something with setting up as a tool that I am missing all together? Any help is greatly appreciated!

*EDIT*

I thought I would add the working code here to help anyone if they have a similar issue.

import arcpy
import os


inFC = arcpy.GetParameterAsText(0)

addText = arcpy.GetParameterAsText(1)

outWorkspace = arcpy.GetParameterAsText(2)

arcpy.AddMessage(inFC)

for fc in inFC.split(";"):
    outFC = os.path.join(outWorkspace, os.path.basename(fc).split(".")[0] + "_" + addText)
    arcpy.AddMessage(outFC)
    arcpy.CopyFeatures_management(fc, outFC)

Thanks

0 Kudos
1 Solution

Accepted Solutions
Luke_Pinner
MVP Regular Contributor

You want to set the Direction=input as outWorkspace is an input to the tool, not an output of the tool. 

Basically anything you use arcpy.GetParameterAsText for is an input parameter, and anything you use arcpy.SetParameterAsText for is an output parameter.

View solution in original post

2 Replies
Luke_Pinner
MVP Regular Contributor

You want to set the Direction=input as outWorkspace is an input to the tool, not an output of the tool. 

Basically anything you use arcpy.GetParameterAsText for is an input parameter, and anything you use arcpy.SetParameterAsText for is an output parameter.

ChrisBrannin
Regular Contributor

I see, thank you.

0 Kudos