Select to view content in your preferred language

Creating table inside .mdb database using arcpy.CreateTable_management. I have an access mdb database and I want to use arcpy.CreateTable_management to create a table inside the .mdb. How?

9284
24
06-03-2016 08:56 AM
PaulHacker2
Deactivated User

I have an access mdb database and I want to use arcpy.CreateTable_management to create a table inside the .mdb.

This works to make the DB using Python:

config_keyword = ""

mdb = ".mdb"

out_folder_path = "C:/output"

out_name = "CountyCode_MapGrid_"

name = "newDB"

arcpy.CreatePersonalGDB_management(out_folder_path, out_name + name + mdb)

And it works fine but to get a table created INSIDE the .mdb using:

   arcpy.CreateTable_management(out_folder_path, "Block_77", config_keyword)

    arcpy.AddField_management(out_name, "OBJECTID", "AutoNumber")

    arcpy.AddField_management(out_name, "SHAPE", "OLE Object")

    arcpy.AddField_management(out_name, "id_block", "Number")

    arcpy.AddField_management(out_name, "id_mapgrid", "Number")

    arcpy.AddField_management(out_name, "map_number", "Short Text")

    arcpy.AddField_management(out_name, "Block", "Short Text")

    arcpy.AddField_management(out_name, "SHAPE_Length", "Number")

    arcpy.AddField_management(out_name, "SHAPE_Area", "Number")

    arcpy.AddField_management(out_name, "created_user", "Short Text")

    arcpy.AddField_management(out_name, "created_date", "Date/Time")

    arcpy.AddField_management(out_name, "last_edited_user", "Short Text")

    arcpy.AddField_management(out_name, "last_edited_date", "Date/Time")

Does not work. Any suggestions?

Thanks!

0 Kudos
24 Replies
PaulHacker2
Deactivated User

So are there any Python script to create Geodatabase from XML Workspace documents?

0 Kudos
BlakeTerhune
MVP Regular Contributor

Paul Hacker​ says:

Now if I can just find some way to use the same CreatePersonalGDB_management/CreateTable_management/AddField_management  to make the database and then in the tables slip in a SHAPE that is a polygon, that would do what I need to be done.

Joshua Bixby​ replied:

...the proper method to create a spatially-enabled table (one with a SHAPE field) is to use the Create Feature Class tool.  The tool does multiple things for you, one it creates a table, and two it adds the spatial field.  The result is a new table with a SHAPE field already defined for you.

If your goal is to create a SHAPE field in a Access table not using Esri tools, the short answer is don't.

There's really nothing more to be said. Not sure why you're so stuck on trying to reinvent the wheel when it comes to making a feature class.

PaulHacker2
Deactivated User

Ok, I used arcpy.CreateFileGDB_management(out_folder_path,out_name) to create the geodatabase

and

arcpy.ImportXMLWorkspaceDocument_management(target_gdb, in_file, import_type) to use the XML to load it with just

the SCHEMA_ONLY.

But how to rename all the tables and fields to match the land tracks for each DB required?

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Alter Field tool or you could edit the XML file before using it to create the new feature classes.

PaulHacker2
Deactivated User

Yep. Using Python to get the list of tracts, then edit a template XML document and create all the XML documents for all the tracts, and then making the new feature classes for each of the tracts. Now it's 'merely a matter of programming!"

0 Kudos