Updating and fixing data sources

772
5
03-12-2021 08:53 AM
SFortnam
New Contributor II

Has anyone had success with updating data sources in ArcGIS Pro with using Python?

https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/updatingandfixingdatasources.htm#ESRI_SECTION...

I have not used Python in ArcGIS Pro and have not gotten this to work, so I'm certain its user error on my part.

0 Kudos
5 Replies
Kara_Shindle
Occasional Contributor III

Can you share any code?

0 Kudos
DanPatterson
MVP Esteemed Contributor

Are you running the code from within the python window within Pro?

That is how the "CURRENT" project is determined.

If you are running it from an external python ide, then that is a different issue


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

Yes, I am attempting to run it within the python window within the Pro project.  I'm trying at this point to just get the dictionary to return on the project - which is why I thought that using the Python window in pro was the best option.  I admit its been while since I've had to use Python, so I ran through some of the tutorials & documents to get caught up to speed, but I'm still having an issue with a basic script.

This is the code from the article -

import arcpy, pprint
p = arcpy.mp.ArcGISProject('current')
m = p.listMaps()[0]
l = m.listLayers()[0]
pprint.pprint(l.connectionProperties)

0 Kudos
DanPatterson
MVP Esteemed Contributor

aprx = arcpy.mp.ArcGISProject("CURRENT")

try some other print statements like

print(m)

print(l)

does that work? you arent showing anything that is returned


... sort of retired...
0 Kudos
CCWeedcontrol
Occasional Contributor III

Here is one I have used but the layer has to be in the same folder.

 

project = arcpy.mp.ArcGISProject('CURRENT')
layer1 = project.listMaps()[0]
lyr = layer1.listLayers('HOMES')[0]

arcpy.env.workspace = os.path.dirname(project.filePath)
wp = os.path.dirname(project.filePath)

#lyr1 = project.listLayers("SUBJECT_PROPERTY")[0]
try:
    cp = lyr.connectionProperties
    cp['connection_info']['database'] = wp
    cp['dataset'] = 'HOMES2.shp'
    lyr.updateConnectionProperties(lyr.connectionProperties, cp)
except:
    pass

 

0 Kudos