Dear Xander Bakker,
Please find the attached for the my pgdb.
I am still getting some error from the script you have sent me. please advise. thanks
I have a geodatabase with multiple feature classes in multiple feature datasets. Each feature class has same fields which are identical and will carry the same value. plzhelp me.
I have fields in the below.
BUILDING_ID
COMMENT
DISCIPLINE_CODE
DRAWING_REFERENCE
FLOOR_ID
OWNERSHIP_CODE
PARCEL_ID
SUBDISCIPLINE_CODE
Thanks
Santhosh
It would be best to create a question and not a document, since now comments do not offer the advanced editor to structure code. Below an example of the code that I executed on a copy of your file geodatabase. Note that the bold line points to a location on my drive. You should change this to the location where you have your data.
However, before you do that, be sure what you are doing. Always make a backup of the data before running the script. You data will be updated.
I noticed that there are many attributes the currently have different values which makes sense. By applying a single value to all features you will probably end up with information which is not valid. Your data has information that identifies the different floors.
By assigning a single value to all the feature, they will all be on the same floor...
Be careful with fields that have coded domain values. You will have to assign a valid code (not description).
import arcpy
import os
import sys
#Set Overwrite Option
arcpy.env.overwriteOutput = True
# additional parameter to provide the workspace
ws = r"D:\Xander\GeoNet\MultiupdateAttribs\COSC_SSUC_PGDB_FINAL.gdb"
# fixed values to assing to fields
building_id = '02'
comment = 'MB'
discipline_code = 'FK'
drawing_ref = 'C0400-GS-0114-01-EL-FA-A0-B2-001-999'
floor_id = 'UR' # coded domain - Upper Roof
ownership_code = '99COSC'
parcel_id = '115'
subdiscipline_code = 'GB'
# create a dictionary with the field name and corresponding value
dct_fld_val = {'BUILDING_ID': building_id,
'COMMENT': comment,
'DISCIPLINE_CODE': discipline_code,
'DRAWING_REFERENCE': drawing_ref,
'FLOOR_ID': floor_id,
'OWNERSHIP_CODE': ownership_code,
'PARCEL_ID': parcel_id,
'SUBDISCIPLINE_CODE': subdiscipline_code}
# fields to update
flds_upd = dct_fld_val.keys()
errs = {}
# you have to set the workspace to be able to use the ListDatasets and ListFeatureClasses
arcpy.env.workspace = ws
fds = arcpy.ListDatasets(feature_type='Feature')
fds.append('') # to include featureclasses that are not within a feature dataset
for fd in fds:
fcs = arcpy.ListFeatureClasses(feature_dataset=fd)
for fc in fcs:
# verify that the fields are actually in the featureclass
print fc
fc_pathname = os.path.join(ws, fd, fc)
flds_fc = [fld.name for fld in arcpy.ListFields(fc_pathname)]
flds = list(set(flds_upd) & set(flds_fc))
# loop through rows of fc
with arcpy.da.UpdateCursor(fc_pathname, flds) as curs:
for row in curs:
for fld in flds:
row[flds.index(fld)] = dct_fld_val[fld]
try:
curs.updateRow(row)
except Exception as e:
err = '{0} - {1}'.format(fc, e)
if err in errs:
errs[err] += 1
else:
errs[err] = 1
for err, cnt in errs.items():
print err, cnt
Dear,
It's working above the code.
Thank you so much your help.
Thanks
Santhosh