Select to view content in your preferred language

Batch Update Data Source in Pro Map - python/CIM

1300
2
Jump to solution
12-22-2022 10:45 AM
ZacharyUhlmann1
Occasional Contributor III

I recall unsuccessfully traversing this topic a couple months ago (did not post here though).  Simple question.  I have multiple layers in an ArcGIS Pro map.  I have created an updated feature class WITHIN the same gdb, but with a different name.  Currently I have 15 layers utilizing the same data source path/to/zachs.gdb/fc_name to path/to/zachs.gdb/fc_name_v2note that the 15 layers have definition queries for 15 different value. I have found the documentation on how to use the cim to change the dataset or gdb underlying the source, but NOT if there is simply a different FC in the same path/to/gdb/<dataset>.

BELOW code adapted from here (https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/updatingandfixingdatasources.htm) BUT there are no methods or properties in the CIM or elsewhere to update my FCs if it's just a name change.  Ideas? Can be with CIM or any module...

p = arcpy.mp.ArcGISProject('current')
m = p.listMaps('zachs_map')[0]
l = m.listLayers('group_w_15_layers')[0]
layer1 = l.listLayers()[1]
layer1_cim = human.getDefinition('V2')
dc = layer1_cim.featureTable.dataConnection
dc.workspaceConnectionString

thanks!

Zach

Pro V. 3.0.02

 

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
RhettZufelt
MVP Notable Contributor

Looks like update connection properties will do that for you.

I'd start with the first example under "Using the connectionProperties dictionary".

R_

 

View solution in original post

2 Replies
RhettZufelt
MVP Notable Contributor

Looks like update connection properties will do that for you.

I'd start with the first example under "Using the connectionProperties dictionary".

R_

 

ZacharyUhlmann1
Occasional Contributor III

You are 100% correct.  I always confuse database and dataSET.  Took me some fumbline, but eventually...Thanks @RhettZufelt !

# Update the Feature Classe(FC) source in TOC via the CIM
# In this example, multiple Layers nested in Group Layer, all same source, 
# with Def Queries to make different.
import copy
p = arcpy.mp.ArcGISProject('current')
m = p.listMaps('map_name')[0]
# Get Layer Group from TOC containing the species layer
spp_group = m.listLayers('spp')[0]
# Now get list of all layers
spp_lyrs = spp_group.listLayers()
# loop through and update layer source FC to species_v2
for spp in spp_lyrs:
    cp = spp.connectionProperties
    cp['dataset']='species_v2'
    spp.updateConnectionProperties(spp.connectionProperties, cp)