1

i just want to write the in_memory table to a table in a .gdb

import arcpy
from arcpy import env
import os
import sys
scriptPath = sys.path[0]
thisFolder = os.path.normpath(os.path.dirname(scriptPath))
env.workspace = os.path.join(thisFolder, "AdminReport", "Workspace")

#get variables
...code here..

#create Table
print("Creating Table...")
tempTable = arcpy.CreateTable_management("in_memory", "tempTable")
arcpy.AddField_management(tempTable, "Parcel_FID", "LONG")
arcpy.AddField_management(tempTable, "Plan_Acres", "DOUBLE")
arcpy.AddField_management(tempTable, "Pres_Acres", "DOUBLE")
arcpy.AddField_management(tempTable, "Conf_Region", "TEXT", field_length=25)
arcpy.AddField_management(tempTable, "Conf_Date", "TEXT", field_length=25)
arcpy.AddField_management(tempTable, "Center_Zone", "TEXT", field_length=25)
arcpy.AddField_management(tempTable, "Center_Muni", "TEXT", field_length=25)

#calculate values for each field
row = arcpy.InsertCursor(tempTable).newRow()
row.setValue("Parcel_FID", objectID)
row.setValue("Plan_Acres", planAcres)
row.setValue("Pres_Acres", presAcres)
row.setValue("Conf_Region", confRegion)
row.setValue("Conf_Date", confDate)
row.setValue("Center_Zone", centerZone)
row.setValue("Center_Muni", centerMuni)
del row

#Output Table to GDB
arcpy.TableToTable_conversion(tempTable, "Workspace.gdb", "outTable")

No errors but I am geting an empty table generated.

1
  • You have already created your table and have added rows to it, so that's not the problem. In addition to using "Copy Features" on a table you're also trying to copy those features (table columns?) to...itself. What is your end goal?
    – Radar
    Commented Sep 25, 2015 at 18:53

2 Answers 2

1

You are missing inserting the row in your insert cursor.

Try this code instead for the cursor:

cursor = arcpy.InsertCursor(tempTable)
row = cursor.newRow()
row.setValue("Parcel_FID", objectID)
row.setValue("Plan_Acres", planAcres)
row.setValue("Pres_Acres", presAcres)
row.setValue("Conf_Region", confRegion)
row.setValue("Conf_Date", confDate)
row.setValue("Center_Zone", centerZone)
row.setValue("Center_Muni", centerMuni)
cursor.insertRow(row)

del cursor
0
1

In your code, outTable is a result object. Apparently this works for AddField_management, but not CopyFeatures_management. A string of the path will work for all code.

Change:

outTable = arcpy.CreateTable_management("in_memory", "outTable")

to:

outTable = arcpy.CreateTable_management("in_memory", "outTable").getOutput (0)

See the Result help.

This and this are good tutorial videos too.

Also, instead of CopyFeatures_management, you might want to try Copy or Table To Table.

4
  • does CreateTable_management copy all of the records in the "in_memory" table? This doesnt seem to work for me
    – its30
    Commented Sep 25, 2015 at 20:52
  • Create Table creates a table with no rows. Commented Sep 25, 2015 at 20:58
  • ok i have updated my code to give you a better idea of what I am attempting to do. I need to end up with a table that has 1 row of values.
    – its30
    Commented Sep 25, 2015 at 21:06
  • arcpy.TableToTable_conversion generates an empty table for some reason
    – its30
    Commented Sep 25, 2015 at 21:07

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.