<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Turning fields on and off using arcpy in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/turning-fields-on-and-off-using-arcpy/m-p/549795#M42956</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Nathan,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Unfortunately, the behavior you are experiencing is "as-designed."&amp;nbsp; However, the visibility can be set as desired in a new layer created using MakeFeatureLayer.&amp;nbsp; Essentially what you need to do is create a Feature Layer with the desired field visibility, remove the original layer from the map, and then add the feature layer. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is a bit cumbersome, however an enhancement request has been logged:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[#NIM087522&amp;nbsp; Please allow field visibility to be changed in an existing map layer.]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 11 Dec 2013 19:14:19 GMT</pubDate>
    <dc:creator>JakeSkinner</dc:creator>
    <dc:date>2013-12-11T19:14:19Z</dc:date>
    <item>
      <title>Turning fields on and off using arcpy</title>
      <link>https://community.esri.com/t5/python-questions/turning-fields-on-and-off-using-arcpy/m-p/549792#M42953</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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 -&amp;gt; field tab the box is still checked next to the indicated field. Is this a bug or am I not using this method properly?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Code below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;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:&amp;nbsp;&amp;nbsp;&amp;nbsp; " + fieldInfo.getVisible(fldIndxNum)

arcpy.RefreshActiveView()
arcpy.RefreshTOC()&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Nathan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Dec 2013 15:02:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/turning-fields-on-and-off-using-arcpy/m-p/549792#M42953</guid>
      <dc:creator>nathanwuenstel</dc:creator>
      <dc:date>2013-12-11T15:02:35Z</dc:date>
    </item>
    <item>
      <title>Re: Turning fields on and off using arcpy</title>
      <link>https://community.esri.com/t5/python-questions/turning-fields-on-and-off-using-arcpy/m-p/549793#M42954</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi there,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try using 'HIDDEN' instead of 'NOT VISIBLE'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;From the FieldInfo help page:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;setVisible (index, visible)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;index&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The index position.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Integer&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;visible&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The visible policy to set into the table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;VISIBLE �??Field is visible.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;HIDDEN �??Field is hidden.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;String&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Dec 2013 15:27:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/turning-fields-on-and-off-using-arcpy/m-p/549793#M42954</guid>
      <dc:creator>ClintDow</dc:creator>
      <dc:date>2013-12-11T15:27:38Z</dc:date>
    </item>
    <item>
      <title>Re: Turning fields on and off using arcpy</title>
      <link>https://community.esri.com/t5/python-questions/turning-fields-on-and-off-using-arcpy/m-p/549794#M42955</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you for the reply Clint,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have replaced 'NOT VISIBLE' with 'HIDDEN'. The script runs as before and outputs:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; Field Name: ARA&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Visible:&amp;nbsp;&amp;nbsp;&amp;nbsp; HIDDEN&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The field remains visible and not hidden and the check box in the fields tab is still checked. It is still not working tho this better follows the online help.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Dec 2013 15:43:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/turning-fields-on-and-off-using-arcpy/m-p/549794#M42955</guid>
      <dc:creator>nathanwuenstel</dc:creator>
      <dc:date>2013-12-11T15:43:38Z</dc:date>
    </item>
    <item>
      <title>Re: Turning fields on and off using arcpy</title>
      <link>https://community.esri.com/t5/python-questions/turning-fields-on-and-off-using-arcpy/m-p/549795#M42956</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Nathan,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Unfortunately, the behavior you are experiencing is "as-designed."&amp;nbsp; However, the visibility can be set as desired in a new layer created using MakeFeatureLayer.&amp;nbsp; Essentially what you need to do is create a Feature Layer with the desired field visibility, remove the original layer from the map, and then add the feature layer. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is a bit cumbersome, however an enhancement request has been logged:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[#NIM087522&amp;nbsp; Please allow field visibility to be changed in an existing map layer.]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Dec 2013 19:14:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/turning-fields-on-and-off-using-arcpy/m-p/549795#M42956</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2013-12-11T19:14:19Z</dc:date>
    </item>
    <item>
      <title>Re: Turning fields on and off using arcpy</title>
      <link>https://community.esri.com/t5/python-questions/turning-fields-on-and-off-using-arcpy/m-p/549796#M42957</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ok. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for the information.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My real intent was to be able to toggle about a dozen fields on and off in a layer. For most of the project we only need to use a few fields but as we are using subtypes, when copying and pasting features back and forth, lots of junk in the attribute tables can get transferred pretty easily regardless of having set all the domains and defaults. The only options that I can see for a layer are to turn all fields on and hide all fields. Writing a script seemed like the way to go but the 'setVisible' method turns out to be quite limited.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In short, is there a way to only turn on the fields that were previously visible? That would be pretty handy.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I know this takes this out of the 'Python' scope and I apologize but I am still seeking an answer to this problem.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Nathan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Dec 2013 01:14:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/turning-fields-on-and-off-using-arcpy/m-p/549796#M42957</guid>
      <dc:creator>nathanwuenstel</dc:creator>
      <dc:date>2013-12-12T01:14:23Z</dc:date>
    </item>
    <item>
      <title>Re: Turning fields on and off using arcpy</title>
      <link>https://community.esri.com/t5/python-questions/turning-fields-on-and-off-using-arcpy/m-p/549797#M42958</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Sure....something like from here (link below) - enter the fields you want to keep in the 'desiredFields' list or use list fields from your orig fc to populate 'desiredFields':&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.arcgis.com/threads/98415-Turn-fields-off-by-script?p=349972#post349972"&gt;http://forums.arcgis.com/threads/98415-Turn-fields-off-by-script?p=349972#post349972&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Dec 2013 10:43:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/turning-fields-on-and-off-using-arcpy/m-p/549797#M42958</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2013-12-12T10:43:24Z</dc:date>
    </item>
    <item>
      <title>Re: Turning fields on and off using arcpy</title>
      <link>https://community.esri.com/t5/python-questions/turning-fields-on-and-off-using-arcpy/m-p/549798#M42959</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have gotten a script to run but I am getting a runtime error, any ideas? the error happens at fields&lt;F&gt;.append(row.getValue(f))&lt;/F&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;from arcpy import env&lt;BR /&gt;arcpy.env.overwriteOutput = True&lt;BR /&gt;arcpy.env.addOutputsToMap = False&lt;BR /&gt;arcpy.env.workspace = "C:/temp"&lt;BR /&gt;out_layer = "temp.lyr"&lt;/P&gt;&lt;P&gt;mxd = arcpy.mapping.MapDocument('CURRENT')&lt;BR /&gt;df = arcpy.mapping.ListDataFrames(mxd, '*')[0] # need to find way to get list of layers there can be more than one data frame&lt;BR /&gt;listfields = []&lt;BR /&gt;thebadlist = []&lt;BR /&gt;for LayerNeedsFieldsTurnedOff in arcpy.mapping.ListLayers(mxd):&lt;BR /&gt;&amp;nbsp;if LayerNeedsFieldsTurnedOff.isGroupLayer: &lt;BR /&gt;&amp;nbsp;&amp;nbsp;print "group print"&lt;BR /&gt;&amp;nbsp;elif LayerNeedsFieldsTurnedOff.isFeatureLayer:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;fields = dict((f.name, []) for f in arcpy.ListFields(LayerNeedsFieldsTurnedOff) if not f.required)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;rows = arcpy.SearchCursor(LayerNeedsFieldsTurnedOff,"","","","")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;for row in rows:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;for f in fields.keys():&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fields&lt;F&gt;.append(row.getValue(f))&lt;/F&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#print row.getValue(f)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;for field, values in fields.iteritems():&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;#print field&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;if &amp;nbsp;field == "Shape": &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;listfields.append(field)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;elif all(map(lambda s: s is None or not str(s).strip(), values)):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;thebadlist.append(field)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;else: &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;listfields.append(field)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;# LayerNeedsFieldsTurnedOff = arcpy.mapping.ListLayers(mxd, 'exampledata', df)[0]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;# fill in your desired fields to remain visible &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;desiredFields = listfields&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;field_info = arcpy.Describe(LayerNeedsFieldsTurnedOff).fieldInfo # I need this for field count&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;for i in range(field_info.count):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;if field_info.getfieldname(i) not in desiredFields:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if field_info.getfieldname(i) == "SHAPE":&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;field_info.setvisible(i, 'VISIBLE')&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;elif field_info.getfieldname(i) == "Shape":&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;field_info.setvisible(i, 'VISIBLE')&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;field_info.setvisible(i, 'HIDDEN')&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;arcpy.SaveToLayerFile_management(LayerNeedsFieldsTurnedOff, out_layer)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;arcpy.MakeFeatureLayer_management(LayerNeedsFieldsTurnedOff, 'temp_layer', '', '', field_info)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;refLyr = arcpy.mapping.Layer('temp_layer')&lt;BR /&gt;&amp;nbsp;&amp;nbsp;# rename the ref layer the same as your target layer&lt;BR /&gt;&amp;nbsp;&amp;nbsp;refLyr.name = LayerNeedsFieldsTurnedOff.name &lt;BR /&gt;&amp;nbsp;&amp;nbsp;lyrfile = "C:/temp/temp.lyr"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;print LayerNeedsFieldsTurnedOff.name&lt;BR /&gt;&amp;nbsp;&amp;nbsp;arcpy.ApplySymbologyFromLayer_management(refLyr, lyrfile)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;arcpy.mapping.UpdateLayer(df, LayerNeedsFieldsTurnedOff, refLyr, False)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;# mxd.save()&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;print 'cleaning up-' &lt;BR /&gt;&amp;nbsp;&amp;nbsp;if arcpy.Exists('temp_layer'):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;print '\'temp_layer\' still in memory...deleting now...'&lt;BR /&gt;&amp;nbsp;&amp;nbsp;arcpy.Delete_management('temp_layer')&lt;BR /&gt;&amp;nbsp;&amp;nbsp;print 'deleting obj refs...'&lt;BR /&gt;&amp;nbsp;&amp;nbsp;del LayerNeedsFieldsTurnedOff, refLyr,&amp;nbsp; fields, f, i&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;print 'done.'&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Sep 2017 21:23:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/turning-fields-on-and-off-using-arcpy/m-p/549798#M42959</guid>
      <dc:creator>DanMacDonald</dc:creator>
      <dc:date>2017-09-18T21:23:58Z</dc:date>
    </item>
    <item>
      <title>Re: Turning fields on and off using arcpy</title>
      <link>https://community.esri.com/t5/python-questions/turning-fields-on-and-off-using-arcpy/m-p/549799#M42960</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Has ESRI updated this yet? I need to be able to use a script to turn off certain fields for a Feature Class without creating a new layer?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 18 Nov 2017 15:06:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/turning-fields-on-and-off-using-arcpy/m-p/549799#M42960</guid>
      <dc:creator>MichaelMcDermott1</dc:creator>
      <dc:date>2017-11-18T15:06:18Z</dc:date>
    </item>
    <item>
      <title>Re: Turning fields on and off using arcpy</title>
      <link>https://community.esri.com/t5/python-questions/turning-fields-on-and-off-using-arcpy/m-p/1130181#M63394</link>
      <description>&lt;P&gt;I find it useful sometimes to run the geoprocessing tool and then right click the green ribbon &amp;gt; Copy Python Command-- that is, if the tool runs successfully. Then copy that into your python editor. You can see how the&amp;nbsp; parameters should look.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JaredPilbeam2_0-1641249093716.png" style="width: 352px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/30659i146D544D45CD3C48/image-dimensions/352x493?v=v2" width="352" height="493" role="button" title="JaredPilbeam2_0-1641249093716.png" alt="JaredPilbeam2_0-1641249093716.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jan 2022 22:31:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/turning-fields-on-and-off-using-arcpy/m-p/1130181#M63394</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2022-01-03T22:31:59Z</dc:date>
    </item>
  </channel>
</rss>

