Is it possible to add a layer file (.lyr) to the active map using code in Pro 3? My Pro 2 code does not work in 3.
Did you see the Map, Layout, and Layer Files and Packages section of the 3.0 Migration Guide?
This will work for lyrx files. Lyr file are from ArcGIS Desktop so i am not sure if 3.0 will still load those.
protected override async void OnClick()
{
string url = @"c:\temp\Acme Service Roads.lpkx"; // load layer file
Uri uri = new Uri(url);
await QueuedTask.Run(() => LayerFactory.Instance.CreateLayer(uri, MapView.Active.Map));
}
To be sure, Pro 3.x will do the appropriate thing with a .LYR file that I drag onto a map. But the Pro SDK steps for adding a LYRX file do not support LYR files (throws `System.Runtime.InteropServices.COMException (0x80004005): Could not determine encoding`). We're trying to transition our users from an ArcMap add-in to a Pro add-in, and we are hoping to skip the step of converting all those LYRs to LYRXs until after the transition is complete (so we can skip supporting twice the amount of layer files during the transition). I'll reply to my own post here if I find a way to do this, but I'd appreciate any guidance anyone might have.
Are you still looking how to load lyr files? I have a custom layer manager add-in I could send your way to try out. If it does what you want, I can pull out the code for you.
Yes please!! I'll send you a direct message . . .