Created
November 26, 2015 23:33
-
-
Save M-Bryant/61ab1add37245b7d8a1b to your computer and use it in GitHub Desktop.
arcpy: create_output_gdb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import arcpy | |
| def create_output_gdb(parent_folder, gdb_name): | |
| """Creates a new gdb in the folder | |
| """ | |
| arcpy.AddMessage("Checking output workspace...") | |
| gdb_path = os.path.join(parent_folder, gdb_name + ".gdb") | |
| # Generate a unique name if the gdb already exists | |
| if arcpy.Exists(gdb_path): | |
| arcpy.AddWarning(" " + gdb_path + " already exists...creating a unique name for the workspace") | |
| unique_name = arcpy.CreateUniqueName(gdb_name + ".gdb", parent_folder) | |
| gdb_path = unique_name | |
| arcpy.AddMessage("Creating GDB: " + gdb_path) | |
| arcpy.management.CreateFileGDB(os.path.dirname(gdb_path), os.path.basename(gdb_path)) | |
| return str(gdb_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment