AnsweredAssumed Answered

Turn fields off by script

Question asked by eibenm on Dec 6, 2013
Latest reply on Dec 9, 2013 by Wayne_Whitley
I've been beating my head against a wall for a full workday trying to figure this one out.  What I want to accomplish is to turn a number of fields off in a feature layer.  There is a method using the fieldInfo() method, but that only seems to work when creating a NEW feature layer.  I want to apply the turned off fields to the EXISTING layer.

Code example below

mxd = arcpy.mapping.MapDocument("CURRENT")  df = arcpy.mapping.ListDataFrames(mxd, "*")[0]  LayerNeedsFieldsTurnedOff = arcpy.mapping.ListLayers(mxd, "Layer Name", df)[0]  desiredFields = ["LAST","FIRST","CITY","ZIP"]  # This makes the field_info object that can then be applied to a layer field_info = arcpy.Describe(LayerNeedsFieldsTurnedOff).fieldInfo for index in xrange(0, field_info.count):     if field_info.getfieldname(index) not in engineFields:         field_info.setvisible(index,"HIDDEN")

This is where I'm not sure what to do, all the examples show making an new layer like:


This however set's me down a rabbit hole I really don't want to go down.  (duplicate layers, symbology, labeling, etc...) Is there a way to apply the field visibilities back to the original layer and not a new one?

Thanks in advance!