Using ArcMap created Layer Files with ArcGIS Pro 3 (ArcPy)

332
3
08-01-2023 06:54 AM
ScottDickison1
New Contributor

I am trying to write a script to convert .lyr files generated with ArcGIS 10.6.1 to ArcGIS Pro 3.0 .lyrx files in the Pro flavored version of ArcPy. In the documentation for the LayerFile class it says that it provides access to .lyr files. When I try this: 

lf = arcpy.mp.LayerFile(r'M:\Production\Layerfile\Address\House Numbers.lyr')

 

It never returns and just hangs. Is the documentation out of date and you can no longer access .lyr files at 3.0? Is there a piece that I'm missing?

 

Thanks,

Scott

0 Kudos
3 Replies
DanPatterson
MVP Esteemed Contributor

LayerFile—ArcGIS Pro | Documentation

you might want to check to see if the links to the original data are broken in the layer file first... perhaps try

listBrokenDataSources ()

first


... sort of retired...
0 Kudos
ScottDickison1
New Contributor

I think that's a method on the LayerFile class. I can't get the instantiation of the class to happen so I can't get that far. I'm using the first code sample and it dies on the lyrFile = arcpy.mp.LayerFile() line. I've checked to see if the file in my example above is a valid layer file and it opens up in both ArcMap 10.6.1 and ArcGIS Pro. It's nothing terribly exciting - address points with an transparent symbol and labeling turned on.

 

0 Kudos
ScottDickison1
New Contributor

While searching for more answers I found this: https://community.esri.com/t5/arcgis-pro-questions/arcpy-mp-layerfile-layer-filename-hangs/td-p/1217.... This fits our situation exactly. The arcpy.env.workspace needs to be pointed to the correct .sde file. However, the instance in the connection properties of layers within the .lyr must match the instance found in the .sde file or the script will hang when trying to instantiate a LayerFile. This gets messy to say the least. I'll keep pecking away at it.

0 Kudos