nwuenstel

Turning fields on and off using arcpy

Discussion created by nwuenstel on Dec 11, 2013
Latest reply on Nov 18, 2017 by mmcdermott2212
Hi,

I am trying to use python to turn fields on and off for layers in my table of contents using the 'fieldInfo.setVisible' method. I can get it to run through and then output as setVisible = "NOT VISIBLE" but the fields remains visible and under the layer properties -> field tab the box is still checked next to the indicated field. Is this a bug or am I not using this method properly?

Code below:

import arcpy

mxd = arcpy.mapping.MapDocument("CURRENT")

### set layer
lyr = "StructurePnt"

fieldList = arcpy.ListFields(lyr)
desc = arcpy.Describe(lyr)

fieldInfo = desc.fieldInfo

### field index number
fldIndxNum = 6

fieldInfo.setVisible( fldIndxNum, 'NOT VISIBLE' )
print "\tField Name: " + fieldInfo.getFieldName(fldIndxNum)
print "\tVisible:    " + fieldInfo.getVisible(fldIndxNum)

arcpy.RefreshActiveView()
arcpy.RefreshTOC()


Thank you,
Nathan

Outcomes