Skip to main content
added 111 characters in body
Source Link
Jason Scheirer
  • 18k
  • 2
  • 54
  • 72

It may be tripping up on the forward slashes, see if this works:

lyr = arcpy.mp.LayerFile(r'C:\gis\layer.lyrx')

for layer in lyr.listLayers():
    layer.updateConnectionProperties(r'C:\old.gdb', r'C:\data\newGDB.gdb')

lyr.saveACopy(r'C:\gis\newLayer.lyrx')

(I suspect lyr.updateConnectionProperties(r'C:\old.gdb', r'C:\data\newGDB.gdb') would do the trick, too).

A layer file can, theoretically, contain multiple layers at its top level so think of it as a container that has-many layers, not a layer itself.

It may be tripping up on the forward slashes, see if this works:

lyr = arcpy.mp.LayerFile(r'C:\gis\layer.lyrx')

for layer in lyr.listLayers():
    layer.updateConnectionProperties(r'C:\old.gdb', r'C:\data\newGDB.gdb')

lyr.saveACopy(r'C:\gis\newLayer.lyrx')

A layer file can, theoretically, contain multiple layers at its top level so think of it as a container that has-many layers, not a layer itself.

It may be tripping up on the forward slashes, see if this works:

lyr = arcpy.mp.LayerFile(r'C:\gis\layer.lyrx')

for layer in lyr.listLayers():
    layer.updateConnectionProperties(r'C:\old.gdb', r'C:\data\newGDB.gdb')

lyr.saveACopy(r'C:\gis\newLayer.lyrx')

(I suspect lyr.updateConnectionProperties(r'C:\old.gdb', r'C:\data\newGDB.gdb') would do the trick, too).

A layer file can, theoretically, contain multiple layers at its top level so think of it as a container that has-many layers, not a layer itself.

added 149 characters in body
Source Link
Jason Scheirer
  • 18k
  • 2
  • 54
  • 72

It may be tripping up on the forward slashes, see if this works:

lyr = arcpy.mp.LayerFile(r'C:\gis\layer.lyrx')

for layer in lyr.listLayers():
    layer.updateConnectionProperties(r'C:\old.gdb', r'C:\data\newGDB.gdb')

lyr.saveACopy(r'C:\gis\newLayer.lyrx')

A layer file can, theoretically, contain multiple layers at its top level so think of it as a container that has-many layers, not a layer itself.

It may be tripping up on the forward slashes, see if this works:

lyr = arcpy.mp.LayerFile(r'C:\gis\layer.lyrx')

for layer in lyr.listLayers():
    layer.updateConnectionProperties(r'C:\old.gdb', r'C:\data\newGDB.gdb')

lyr.saveACopy(r'C:\gis\newLayer.lyrx')

It may be tripping up on the forward slashes, see if this works:

lyr = arcpy.mp.LayerFile(r'C:\gis\layer.lyrx')

for layer in lyr.listLayers():
    layer.updateConnectionProperties(r'C:\old.gdb', r'C:\data\newGDB.gdb')

lyr.saveACopy(r'C:\gis\newLayer.lyrx')

A layer file can, theoretically, contain multiple layers at its top level so think of it as a container that has-many layers, not a layer itself.

Source Link
Jason Scheirer
  • 18k
  • 2
  • 54
  • 72

It may be tripping up on the forward slashes, see if this works:

lyr = arcpy.mp.LayerFile(r'C:\gis\layer.lyrx')

for layer in lyr.listLayers():
    layer.updateConnectionProperties(r'C:\old.gdb', r'C:\data\newGDB.gdb')

lyr.saveACopy(r'C:\gis\newLayer.lyrx')