I created a Python Script tool to create a GDB inside of a user defined folder path. I am trying to find a way to add another parameter in my script tool for a user to input a shapefile after they created their GDB. The shapefile would be converted into a feature class and stored inside the user created GDB. I have been having trouble making a connection between the shapefile the user enters and then storing it inside the geodatabase.
Code:
#Importing Modules/Creating Function
import arcpy
import os
#Function to create GDB
def gdbbuilder(gdbnames):
arcpy.AddMessage("...Starting Function")
if arcpy.Exsists(currentdir):
arcpy.Delete_management(currentdir)
else:
pass
currentdir = arcpy.GetParameterAsText(0)
projectname = currentdir.split("\\")[-1]
for gdbname in gdbnames.split(";"):
newgdbname= "{}_{}".format(projectname,gdbname)
arcpy.management.CreateFileGDB(currentdir, newgdbname, "Current")
#Creating Second & Third User parameter
gdbnames = arcpy.GetParameterAsText(1)
inputlyr = arcpy.GetParameterAsText(2)
arcpy.CopyFeatures_management(inputlyr,currentdir)
My thought process was that the user could create the gdb first then use the inputlyr(shpfile) and the currentdir(gdb) as parameters for the copy feature function to create a featureclass in that gdb. However, I recieve
Creating GDB in folder. Traceback (most recent call last): File "C:\Arcpy\GDBcreator.py", line 31, in <module> arcpy.CopyFeatures_management(inputlyr,currentdir) NameError: name 'currentdir' is not defined as the output error.
defstatement.