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
Solved! Go to Solution.
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.
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.
I see, thank you.