0

I've been trying to turn all fields of a layer through properties fields

I just need to turn them all on

 import arcpy
 from arcpy import env
 import sys
 import os
 mxd = arcpy.mapping.MapDocument("CURRENT")
 df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
 for lyr in df:
 if lyr.name == "roads":
 lyr.visible = True
 arcpy.RefreshTOC()
 arcpy.RefreshActiveView()
##Then here I want to turn all fields on of the layer name roads
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Oct 2, 2018 at 14:22
1
  • I think that you would need to start a new loop, something like this: field_info = desc.fieldInfo for index in xrange(0, field_info.count): fieldInfo.setVisible( index, 'VISIBLE' ) Commented Oct 2, 2018 at 15:30

1 Answer 1

4
lyr = r"path to your dataset"
fldlist = arcpy.ListFields(lyr)
fieldinfo = ""
doc = arcpy.mapping.MapDocument("CURRENT") # Current mxd
df = arcpy.mapping.ListDataFrames(doc)[0] # First dataframe
for fld in fldlist:
 fieldinfo = fieldinfo + fld.name + " " + fld.name + " VISIBLE;"
nlyr = arcpy.MakeFeatureLayer_management(lyr,"new layer name","#","#",fieldinfo) # Create the feature layer
arcpy.mapping.AddLayer(df,nlyr) # Add new layer to current mxd

To hide the fields, change "VISIBLE" to "HIDDEN".

You'll need to get the field list, set the fieldInfo, then apply it in makefeaturelayer. You cannot change the fieldInfo properties of a layer that is already in the mxd, so you have to create a new layer with the fieldInfo set to visible.

I am adding this answer because this question hasn't been answered here before. Generally, you should show some more effort in your question, not just "here's my code, please finish it for me." Tell us what you've tried, where you're stuck.

answered Oct 2, 2018 at 15:51
2
  • You're right I should put more context to my question. You mean it is impossible to Turn All Fields On command from the Table Options menu in a layer without creating a new layer!? Commented Oct 2, 2018 at 17:23
  • It's not possible through arcpy. it's been added as a feature request to esri, but they haven't added the functionality yet. Commented Oct 2, 2018 at 17:25

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.