I am using ArcGIS Pro 2.9.3. I am a seasoned Python programmer, but need help meeting the following requirements:
- Environment: A Python toolbox in an ArcGIS Pro project, opened by a user who is manually running the tools
- A map in an ArcGIS Pro project contains several layers that come from feature classes in an enterprise geodatabase feature dataset which is registered as versioned (traditional)
- Read the values of some unselected records in various layers in the map. I will use arcpy.da.SearchCursor with a where clause.
- Update some values of some unselected records in various layers in the map. I will use arcpy.da.UpdateCursor, again with a where clause.
I cannot figure out what combination of strings that arcpy.da methods need, given my environment. I will only know which map layer the user wants to work with at run-time. Its data source will be a feature class in a versioned dataset on an enterprise geodatabase. Given the variables below, which values will make arcpy.da methods happy, so I can Search, Update, Insert, and Delete rows from a layer, regardless of selection, and still be able to see those changes within the map?
projectName = "CURRENT"
project = arcpy.mp.ArcGISProject(projectName)
mapName = "Map"
map_ = next(filter(lambda m: m.name == mapName, project.listMaps()))
grpLayerName = "theGroup"
mapLayerName = "theLayer"
mapLayerLongName = "\\".join((grpLayerName, mapLayerName))
layer = next(filter(lambda lyr: lyr.longName == mapLayerLongName, map_.listLayers()))
dbName = "obfuscated"
schemaName = "adminUser"
datasetName = "bigDataSet"
datasetLongName = ".".join((dbName, schemaName, datasetName))
featClassName = "bigFeatureClass"
featClassLongName = ".".join((dbName, schemaName, featClassName))
sdePath = r"C:\Users\Myself\Documents\ArcGIS\Projects\BigProject"
sdeFileName = "enterprise.sde"
sdeFilePath = os.path.join(sdePath, sdeFileName)
desc = arcpy.da.Describe(layer)
# desc.catalogPath equals os.path.join(sdeFilePath, datasetLongName, featClassLongName)
# desc.path equals os.path.join(sdeFilePath, datasetLongName)
# SOMETIMES, however, an .sde file in a Temp path is seen, rather than the
# one in my project!
# desc.aliasName, baseName, file, and name all equal featClassLongName
arcpy.da.Editor(workspace argument?)
arcpy.da.UpdateCursor(in_table argument?)
I have tried so many combinations of strings for the workspace and in_table arguments, it's not even funny. I get errors like:
- "Objects in this class cannot be updated outside an edit session"
- "cannot open workspace"
- "insufficient permissions" (even though the user editing is the owner)
- Or I succeed with the edit, but the map can't see it until I go to Contents > right-click the database connection and select Refresh. I'm okay refreshing the map or the table view, but I don't want to have to ask the user to refresh the connection
Any help, ideas, or guidance would be appreciated.