Has anyone had success with updating data sources in ArcGIS Pro with using Python?
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.
Can you share any code?
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
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)
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
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