Updating Feature Layers in ArcGIS Pro

428
1
02-20-2019 06:27 AM
AndrewDolch2
New Contributor III

I have wrote the following script to update the locations of the ArcGIS Pro

 

import arcpy, os
aprx = arcpy.mp.ArcGISProject('current')
lyrFolder = "Z:\\ArcGIS_PRO_Migration\\layerfiles\\"
listFC = aprx.listBrokenDataSources()
for fc in listFC:
   lyrFC = str(fc) + (".lyrx")
   lyrfile = os.path.join(lyrFolder, lyrFC)
   maps.addLayer(lyrfile)
   maps.removeLayer(fc)
aprx.save()

When I go to run it I get the following error 

Traceback (most recent call last):
File "<string>", line 8, in <module>
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\utils.py", line 191, in fn_
return fn(*args, **kw)
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\_mp.py", line 1289, in addLayer
return convertArcObjectToPythonObject(self._arc_object.addLayer(*gp_fixargs((add_layer_or_layerfile, add_position), True)))
ValueError: Z:\ArcGIS_PRO_Migration\layerfiles\Charleston_County_routesAnno.lyrx

However,  I have created the layer file and it does exist.   What is going on with the script?   Is there something I need to improve on or  does ArcGIS pro not replace layers automatically.  Also I have tried the replace layers knowledge base and it does not replace any layers. 

0 Kudos
1 Reply
MichaelVolz
Esteemed Contributor

I would add some print statements in the appropriate pro python format to see if paths and variables being passed are what you are expecting.

If the paths and variables are ok, I would double-check help to ensure tool parameters are in the correct format (feature layer and opposed to path to feature class).