Python Script to Set Fields to "Read Only" in ArcGIS Pro

483
4
07-01-2020 12:48 PM
LauraCarson
New Contributor II

Hi everyone!

I'm encountering a strange roadblock and was looking to see if anyone else has experienced this.

I am trying to write a python script that will turn some of my fields to "read only" within my ArcPro project. My current script that that I have written will turn all fields to "read only" for the sake of testing. I have added a message to double check the properties of the field to confirm that it has been set to "read only." However in my current project, my fields still show as unchecked for the "read only" property. 

Has anyone else been able to configure a script that would allow fields to retain this setting in their project? I was thinking maybe it had something to do with saving my project? Below is a copy of my script. Any help would be greatly appreciated!

import arcpy

# Set variables
project = arcpy.mp.ArcGISProject('CURRENT')
map = project.listMaps('Map')[0]
layer = arcpy.GetParameterAsText(0)

desc = arcpy.Describe(layer)
for field in desc.fields:
field.editable = False
arcpy.AddMessage(field.editable)
4 Replies
DanPatterson
MVP Esteemed Contributor
Updating a field property only updates the field object, no changes are made to the actual field in the table or feature class.

You would have more luck using

Alter Field—Data Management toolbox | Documentation 

where you can alter field properties as well as field names


... sort of retired...
0 Kudos
LauraCarson
New Contributor II

Thank you, Dan for your response! Unfortunately the Alter Field tool from the Data Management toolbox does not change the read-only property.

0 Kudos
DanPatterson
MVP Esteemed Contributor

My bad... I think critical things probably need to be set up during the creation phase


... sort of retired...
0 Kudos
VinceDoelman
New Contributor

Dear Laura,

I am running into the exact same issue. I was wondering if you've found a solution yet?

Sincerely,

Vince

0 Kudos