Feature Class to Geodatabase error--ArcGIS Pro

563
2
09-02-2019 07:23 PM
JohnMcCoy2
New Contributor

Using ArcGIS Pro I built a model to create a file geodatabase and import shapefiles to it. When run in Model Builder, it completes successfully. Then I exported the model to a Python script and ran it from a command prompt. It went through the motions but instead of importing the shapefiles, it merely copied the shapefiles to the folder where the newly-created fgdb is located, leaving the fgdb empty. #Anyone have an idea what went wrong?

Here is the Python script generated by ArcGIS Pro. I have changed the actual folder and file names.

# -*- coding: utf-8 -*-
"""Generated by ArcGIS ModelBuilder on: 2019-09-02 11:10:24
All ModelBuilder functionality may not be exported. Edits may be required for equivalency with the original model.
"""

import arcpy

# To allow overwriting the outputs change the overwrite option to true.
arcpy.env.overwriteOutput = False

# Local variables:
AAA_shp = r"C:\XXX\database\ShapeFiles\AAA.shp"
BBB_shp = r"C:\XXX\database\ShapeFiles\BBB.shp"
CCC_shp = r"C:\XXX\database\ShapeFiles\CCC.shp"
DDD_shp = r"C:\XXX\database\ShapeFiles\DDD.shp"
database = r"C:\XXX\database"
YYYY_gdb = database
YYYY_gdb__2_ = YYYY_gdb

# Process: Create File Geodatabase
arcpy.CreateFileGDB_management(out_folder_path=database, out_name="YYYY", out_version="CURRENT")

# Process: Feature Class To Geodatabase
arcpy.FeatureClassToGeodatabase_conversion(Input_Features=r"C:\XXX\database\ShapeFiles\AAA.shp;C:\XXX\database\ShapeFiles\BBB.shp;C:\XXX\database\ShapeFiles\CCC.shp;C:\XXX\database\ShapeFiles\DDD.shp", Output_Geodatabase=YYYY_gdb)

0 Kudos
2 Replies
JohnMcCoy2
New Contributor

A colleague found the problem to be an incorrect command in the Python script exported by Model Builder.  The script points to the gdb folder but needs to point to the gdb file in that folder.

Incorrect:       YYYY_gdb = database

Correct:         YYYY_gdb = "{}\\YYYY.gdb".format(database)

0 Kudos
JoeBorgione
MVP Emeritus

Take model builder to python with a grain of salt.  I've never heard of anyone executing it and not having at least one or two 'little issues'and that predates Pro....

That should just about do it....
0 Kudos