Michael & Caleb- I thought I had the code(s) good to go - but apparently I was wrong and starting to get a little frustrated because I do not understand what I am doing wrong. I can get the code to work just fine BUT with only (1) field at a time. When I add multiple fields to my list in both codes - it does not update anything.Here is the MemoryTableTools.py code:
mport arcpy
from arcpy import env
from MemoryTableTools import *
#Set environment settings
env.workspace = "C:\\MEWCo GIS System\\Electric System\\MEWCo_Electric_Model-LOCAL.gdb"
# Set Local variables
inFeatures = "SERVICE_LOCATION"
joinField = "POLE_NUMBER"
joinField2 = "MAPNO"
joinTable = "CIS_Account_Data"
up_fields = ['CUSTOMER_NAME', 'ACCOUNT_NUMBER', 'TWACS_NUMBER', 'ACCOUNT_STATUS']
jn_fields = ['CUSTNAME', 'ACCOUNTNO', 'METERNO', 'ACCOUNT_STATUS_DESC']
# Run Attribute Update
MemoryTableTools.AttributeUpdate(inFeatures, 'POLE_NUMBER', up_fields, joinTable,'MAPNO',jn_fields)
Here is the other Python script that I am using to run the update:
import sys, traceback, arcpy, os
from os import path as p
def AttributeUpdate(source_table, in_field, update_fields, join_table, join_key, join_values):
try:
""" Updates fields from one table to user defined fields in another table"""
# Check input parameters
if not arcpy.Exists(source_table):
print source_table + ' not found!\nPlease verify that full path of table exists'
sys.exit()
if not arcpy.Exists(join_table):
print join_table + ' not found!\nPlease verify that full path of table exists'
sys.exit()
if in_field not in [f.name for f in arcpy.ListFields(source_table)]:
print in_field + ' not found in ' + p.basename(source_table)
sys.exit()
if join_key not in [f.name for f in arcpy.ListFields(join_table)]:
print join_key + ' not found in ' + p.basename(join_table)
sys.exit()
for fld in update_fields:
if fld not in [f.name for f in arcpy.ListFields(source_table)]:
print fld + ' not found in ' + p.basename(source_table)
print 'Please verify that field names match in ' + p.basename(source_table)
sys.exit()
for fldb in join_values:
if fldb not in [f.name for f in arcpy.ListFields(join_table)]:
print fldb + ' not found in ' + p.basename(join_table)
print 'Please verify that field names match in ' + p.basename(join_table)
sys.exit()
if not type(join_values) == list:
join_values = list(join_values)
if not type(update_fields) == list:
update_fields = list(update_fields)
# Make sure there is matching number of join and update fields
update_dict = {}
if len(update_fields) == len(join_values):
for i in range(len(update_fields)):
update_dict[join_values] = update_fields
for k,v in update_dict.iteritems():
# Create Dictionary
path_dict = {}
srows = arcpy.SearchCursor(join_table)
for srow in srows:
keyrow = srow.getValue(join_key)
valrow = srow.getValue(k)
path_dict[keyrow] = valrow
# Update Cursor
urows = arcpy.UpdateCursor(source_table)
for row in urows:
upkey = row.getValue(in_field)
try:
if upkey in path_dict:
row.setValue(v, path_dict[upkey])
urows.updateRow(row)
except:
pass # skip nulls
print '\'%s\' field in "%s" updated successfully' %(v, p.basename(source_table))
del row, urows, srow, srows
else:
print 'ERROR: Number of update fields and value fields does not match'
except:
print '\nERROR in AttributeUpdate Function.\nPlease Check input parameters and try again.'
if __name__ == '__main__':
shp = r'C:\MEWCo GIS System\Electric System\MEWCo_Electric_Model-LOCAL.gdb\Electric\SERVICE_LOCATION'
dbf = r'C:\MEWCo GIS System\Electric System\MEWCo_Electric_Model-LOCAL.gdb\CIS_Account_Data'
# Attribute Update
up_fields = ['CUSTOMER_NAME', 'ACCOUNT_NUMBER', 'TWACS_NUMBER', 'ACCOUNT_STATUS']
jn_fields = ['CUSTNAME', 'ACCOUNTNO', 'METERNO', 'ACCOUNT_STATUS_DESC']
AttributeUpdate(shp,'POLE_NUMBER',up_fields,dbf,'MAPNO',jn_fields)
Can you take a quick look and see what I am doing wrong - why I can get it to work with (1) field but when I add additional fields to it - it will not work at all.Thank you