POST
|
I'm currently working on a script that will take 5 parameters from the user: a workspace, a new folder name, 2 file GDBs, and a feature class. The script will create a new folder inside the workspace specified by the user. I needed the new name variable to get the full name of one of the file GDBs with the slash in front of it in order to create a file path. db1 then gets copied to the new folder. Everything down to the copy function works. I'm having issues with the append function. I need the append to take a feature class from DB2 and append it to the feature class in DB1. But whenever I run the script, I get the following error: ExecuteError: Failed to execute: Parameters are not valid. ERROR 000338: Inputs must be either all Feature Classes, Tables or Rasters; not mixed. Failed to execute (Append). I understand that I need my input and target to both have the Feature Class data type. Based on what I've coded, DB2_Figure8 is being read as a string due to the GetParameterAsText function. The westFigure8 variable is also a string. The westFigure8 variable is supposed to be a file path into the copied file GDB to access one of the feature classes in that file GDB. So I have 2 strings that need to have the Feature Class data type instead but I'm not sure how to make that happen. Any suggestions would be greatly appreciated! #import necessary modules import arcpy #Get parameters set by user. arcpy.env.workspace = arcpy.GetParameterAsText(0) #sets the workspace folderName = arcpy.GetParameterAsText(1) #allows user to name the folder. folder name should be the date i.e. #mmddyy DB1 = arcpy.GetParameterAsText(2) #the file GDB that will be copied to the new location DB2 = arcpy.GetParameterAsText(3) #the second file GDB that will be appended to the original file GDB DB2_Figure8 = arcpy.GetParameterAsText(4) #the TCOMM_FIGURE8 feature class from the second file GDB newFolder = arcpy.CreateFolder_management(arcpy.env.workspace, folderName) #creates the new folder with data #type Folder newName = DB1[-13:] #takes the string which contains the file path for the file GDB that will be copied and truncates #the name so it is left with the final slash to the end of the file name i.e. \WestTTMP.gdb newPath = str(newFolder) + newName #takes the new folder and converts to a string then combines it with the #truncated file name to create a new file path for the file GDB arcpy.Copy_management(DB1, newPath) #takes the DB1 file GDB and copies it to the new location westFigure8 = newPath + "/" + "TCOMM_FIGURE8" arcpy.Append_management("DB2_Figure8", "westFigure8", "TEST", "", "")
... View more
11-06-2019
08:25 AM
|
0
|
4
|
1035
|
POST
|
Ha! I forgot something so simple! My script now works the way I want it to! Thanks for the help!
... View more
03-28-2019
10:44 AM
|
0
|
1
|
1682
|
POST
|
So here's the code I have. I just ran like this. It'll create the GDB but the result of the clip tool gets stored at the workspace level rather than being stored in the GDB. I must have been using some bad data earlier which may have been causing the output to have no records. The output now has records. However, I want a feature class stored inside the GDB rather than a shapefile. arcpy.env.workspace = arcpy.GetParameterAsText(0)
RouteLayer = arcpy.GetParameterAsText(1)
StateLayer = arcpy.GetParameterAsText(2)
StateTaxDistricts = arcpy.GetParameterAsText(3)
FileGDB_Name = arcpy.GetParameterAsText(4)
GDB = arcpy.CreateFileGDB_management(arcpy.env.workspace, FileGDB_Name).getOutput(0)
stateName = os.path.basename(StateLayer).rstrip(os.path.splitext(StateLayer)[0])
name = stateName[:-1]
clipLayer = arcpy.Clip_analysis(RouteLayer, StateLayer, GDB + name + "_Clip")
... View more
03-28-2019
10:04 AM
|
0
|
3
|
1682
|
POST
|
That still gives me a result with no records. I want to keep the name variable in there. That is holding the name of the state for each clip layer (i.e. name = "Texas"). For example, an output would be something like .......New.gdb\TexasClip which is why I thought NewLocation + name + "Clip" would work.
... View more
03-28-2019
08:32 AM
|
0
|
2
|
1682
|
POST
|
I just tried that. The script will run but the results don't have any records. Is there another way to create the GDB and store as a variable? Maybe I'm not understanding the whole .getOutput(0) thing. Sorry, it's been a while since I've done any python. I did some in college 4 years ago but never thought I would actually be using it.
... View more
03-28-2019
08:03 AM
|
0
|
4
|
1682
|
POST
|
I'm working on a script that originally had locations coded in but I want to make it where anyone in my office can use it and they can set their workspace up however they want. I've almost got it to work how I want. I think I have one more obstacle then I'm good. I have some parameters set up for user input. arcpy.env.workspace = arcpy.GetParameterAsText(0) FileGDB_name = arcpy.GetParameterAsText(1) NewLocation = arcpy.CreateFileGDB_management(arcpy.env.workspace, FildGDB_Name) clipLayer = arcpy.Clip_analysis(RouteLayer, StateLayer, NewLocation + name + "Clip") RouteLayer and StateLayer are additional parameters set up by the user. The script fails when it gets to the clip tool. I realize the way I have it set up, NewLocation calls the CreateFileGDB tool rather than the location of the GDB. I want to be able to create the GDB and store it as a variable so it can be used in other tools in the script. Could someone shed some light on how to do this? Thanks!
... View more
03-28-2019
07:17 AM
|
0
|
10
|
2288
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|