1

I want a tool that does two things: Update symbology, and hide some fields. I created a script tool for that:

import arcpy

in_features = arcpy.GetParameter(0)
ref_lyrx = r"C:\ArcGIS\LAYER\Symbologylayer.lyrx"

aprx = arcpy.mp.ArcGISProject("CURRENT")
myMap = aprx.listMaps('Map')[0]
myLayer = myMap.listLayers("inputLayer")[0]

desc = arcpy.Describe(myLayer)
field_info = desc.fieldInfo
fieldsToHide = "HideThisField"

for i in range(0, field_info.count):
    if field_info.getFieldName(i) in fieldsToHide:
        field_info.setVisible(i, "HIDDEN")
        myLayer.transparency = 50
        arcpy.AddMessage(field_info.getVisible(i))
        arcpy.AddMessage(field_info.getFieldName(i))
        arcpy.ApplySymbologyFromLayer_management(myLayer, ref_lyrx)

aprx.save()

This code runs without any issues. The final for loop there is where the action happens:

  • Set field to hidden - But it does not hide on the attribute table, it is still there
  • Change layer transparency - Works, layer gets transparent
  • Print the status of the field - Prints "HIDDEN". If I delete the setVisible above, it shows "VISIBLE" instead.
  • Print the field name - The correct field that should be hidden shows here. Just for diagnosis.
  • Apply Symbol from another Layer - Does not work

The results are confusing. Why the transparency changes, but the rest does not? Why it change the status of my field to hidden, but this change does not reflect on map? Why ApplySymbology don't work (if I run the arcgis tool, it does).

  • Have you tried refreshing your active view and refreshing the attribute table? – Emil Brundage Sep 26 at 20:53
  • Yes. Both refreshing and opening/closing the project. – Gustavo Sep 26 at 21:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.