I am using ArcGIS Desktop 9.3.

What I am looking to do is create a file geodatabase and add a feature class directly into that file geodatabase, as opposed to creating a feature class outside the file geodatabase and then importing it into the file geodatabase. The reason I need to be able to create the feature class directly in a file geodatabase is because I need to have attribute table columns that are nullable, whereas if I create a feature class outside the file geodatabase and then import it into the file geodatabase, nulls will not be allowed. Please correct me if I am wrong. Currently, I am able to create the file geodatabase, but I can't add a feature class directly to the file geodatabase. The code I currently have is:

 import os, arcgisscripting
 gp = arcgisscripting.create(9.3)
 gp.Overwriteoutput = 1
 cwd = "C:\\Path\\To\\directory"
 gp.workspace = cwd
 gp.toolbox = "management"
 number = '1'
 fileGDB = "test_%s.gdb" % number
 shpFile = "file_%s.shp" % number
 gp.CreateFileGDB(cwd, fileGDB)
 gp.CreateFeatureclass(fileGDB, shpFile, "POINT", '#', '#', '#', '#')
 gp.addfield ( shpFile, fieldName, "FLOAT", "20","20", "#", "#", "NULLABLE", "#", "#")
 ...the rest of my code here
  • Why are you using a modulus when defining your file GDB and shpFile name?
    – Nathanus
    Commented Jul 8, 2011 at 21:13
  • 1
    @Nathanus: in this context % is a string formatting operator, so the result is 'test_1.gdb'
    – Mike T
    Commented Jul 8, 2011 at 22:15
  • @9monkeys: you have a subtle typo with "C:\Path\\To\\directory" .. make this either "C:\\Path\\To\\directory" or r"C:\Path\To\directory"
    – Mike T
    Commented Jul 8, 2011 at 22:19
  • Are you trying to import a shapefile into the GDB? In that case you would use FeatureClassToFeatureClass. I think you do have some terminology confused.
    – Sean
    Commented Jul 9, 2011 at 15:28
  • @Mike Yes, thanks, that was a typo. I don't want to import a shapefile into the GDB because the shapefile needs to be able accomodate nulls, which shapefiles can't (see this very interesting post forums.esri.com/Thread.asp?c=93&f=993&t=125464) while GDBs can. That being said, if I build the shapefile outside of the GDB then I won't be able to use nulls whereas if I build inside of a GDB then I can use nulls.
    – 9monkeys
    Commented Jul 11, 2011 at 12:13

2 Answers 2


I think your first problem is that you're appending ".shp" to your output geodatabase featureclass. Remove this and your problem may be solved.

shpFile = "file_%s" % number  #--removed ".shp"
...the rest of your code here

Since the steps you are doing comprise of geoprocessing tools, you could just build it in ModelBuilder and export out the script to python. I did this in 9.3.1, I'm not sure if the script is the same in 9.3, see code below.

# Import system modules
import sys, string, os, arcgisscripting

# Create the Geoprocessor object
gp = arcgisscripting.create()

# Load required toolboxes...
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")

# Local variables...
test_gdb = "C:\\Temp\\test.gdb"
Temp = "C:\\Temp"
fclass = "C:\\Temp\\test.gdb\\fclass"
test_gdb__2_ = "C:\\Temp\\test.gdb"
fclass__2_ = "C:\\Temp\\test.gdb\\fclass"

# Process: Create File GDB...
gp.CreateFileGDB_management(Temp, "test")

# Process: Create Feature Class...
gp.CreateFeatureclass_management(test_gdb__2_, "fclass", "POLYGON", "", "DISABLED", "DISABLED", "", "", "0", "0", "0")

# Process: Add Field...
gp.AddField_management(fclass, "number", "LONG", "2", "", "", "", "NULLABLE", "NON_REQUIRED", "")

You may have to reference the toolboxes that you are using.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.