I am trying to produce a script that populates several fields within various feature classes I select. I am currently trying to build a list of feature classes from table of content items in an mxd. Then, I plan on using this list as input to a function (Populate) that populates the values for standardized fields.
The feature classes whose fields I will need to populate may not be gathered in a single workspace. And I may not want to perform this function on all feature classes within a particular workspace.
It seems a variable number of arguments may be necessary and that is what I have tried to perform with script similar to that shown below. The script below results in a runtime error: IOError: "[u'NameOfAFeatureClass']" does not exist.
Comments in script identify some of my attempts to debug. I am running this script in the ArcMap Python window. I need to determine why the Populate function is not finding the feature classes.
mxd = arcpy.mapping.MapDocument("CURRENT")
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.supports("DATASOURCE"):
mylist = []
mylist.append(lyr.name) # also tried mylist.append(lyr)
''' I tried creating a function too:
def MxdFCs():
mxd = arcpy.mapping.MapDocument("CURRENT")
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.supports("DATASOURCE"):
mylist = []
mylist.append(lyr)
return mylist
MxdFCs()
'''
def Populate(*args):
FieldOne = arcpy.ListFields(args, 'FieldOne')
for field in FieldOne:
if field.name == 'FieldOne':
arcpy.CalculateField_management(args, 'FieldOne',
expression='999',
expression_type='PYTHON_9.3')
FieldTwo = arcpy.ListFields(args, 'FieldTwo')
for field in FieldOne:
if field.name == 'FieldTwo':
arcpy.CalculateField_management(args, 'FieldTwo',
expression='999',
expression_type='PYTHON_9.3')
Populate(*mylist)