AnsweredAssumed Answered

hide fields and export table through python

Question asked by rbasaria_DTS on Sep 27, 2017
Latest reply on Feb 12, 2018 by ahmadabusaleh



I am building a script to run as an ArcGIS tool that takes a line file and does a bunch of stuff to it, then exports a table and uses that table to make route events.

I do not need, nor do I want, all of the fields from the original line file in the layer events attributes table. As such, I have been working on a way to export only the necessary fields from the feature class to a table for use in the make route even layers tool.

Here is what I have so far:


#Hide all fields that are not required for samples.
keepFieldList = ["SAMPLE_ID", "SEGMENT_ID", "NAME", "LENGTH", "WIDTH", "BEGIN_MP", "END_MP"]
fieldInfo = arcpy.FieldInfo()
fieldList = arcpy.ListFields(sampevents)
for field in fieldList:
    if in keepFieldList:
        fieldInfo = fieldInfo + field.Name + " " + + "VISIBLE;"
        fieldInfo = fieldInfo + field.Name + " " + + "HIDDEN;"
#Export sample events to table for use in make route event layer.
arcpy.TableToTable_conversion(sampevents, gisdata, "Sample_Events_Table")


Here is the traceback info (Note that line 157 in the full script is line 9 in the above portion):


Traceback (most recent call last):
File "C:\Projects\CreateSamples\", line 157, in <module>
fieldInfo = fieldInfo + field.Name + " " + + "HIDDEN;"
AttributeError: 'Field' object has no attribute 'Name'

Failed to execute (CreateSamples).


Thanks for any help resolving this. I am not entirely sure what the error is saying. My idea here is to hide all fields not in the keepFieldList and then export those fields to a new table. Then that table will be used as the event table input in the make route events tool.