Now I cannot do that. I need to change schema name (schema.tablename) in big set of symbolized layers. Repair datasource of course doesn't work, definition query is different thing as well. I realized that I can't automate my task with arcpy.
Is there any update on this idea with python 3.x that is shipped with Pro?
A fix was made in Pro 3.2 that enables modifying query layers via Python CIM Access. We will post a sample to this page.
This is possible using ArcGIS Pro version 3.2. In the Updating Data Sources help topic, go to the CIM Section, and check out the third code sample:
# Reference project, map and layer
p = arcpy.mp.ArcGISProject(r'C:\Projects\USA.aprx')
m = p.listMaps('USA')[0]
l = m.listLayers('States')[0]
# Get the layer's CIM definition
lyrCIM = l.getDefinition('V3')
# Update the sql query where clause for the layer
sql = lyrCIM.featureTable.dataConnection.sqlQuery
newsql = sql.replace("WHERE SUB_REGION = 'Mtn'", "WHERE SUB_REGION = 'Pacific'")
lyrCIM.featureTable.dataConnection.sqlQuery = newsql
# Set the layer's CIM definition
l.setDefinition(lyrCIM)
The above sample changes the sql query, but other properties of the Query Layer can also be updated.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.