Hi all.
I'm developing an ArcGIS Pro plugin. I would like to set the properties of a layer based on a layer files (.lyrx) that I would like to provide as part of the plugin deployment.
Therefore I used the LayerDocument class, constructed from a layer file path:
var lyrDocFromLyrxFile = new LayerDocument(@"c:\data\layer.lyrx");
However, this seem to require an absolute path, and therefore this layer file must be installed there by the user.
I can add the layerfile to the solution such that it is distributed with the plugin package. How do I construct a proper path to the resource in the package. Since the package is just a zip-file, and the resource is put with the dlls in the Install folder, I would expect the following to work:
var dllPath = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
var layerFile = System.IO.Path.Combine(dllPath, @"Install\LayersFiles\KILOMETERRIBBON.lyrx");
var lyrDocFromLyrxFile = new LayerDocument(layerFile);
However this provides an empty layer definition.
Hi Rob,
CodeBase property is not suitable for your case. To get the absolute path to the loaded manifest-containing file, use the Assembly.Location property instead.
var dllPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
Then take directory name from Location and do not use Install folder:
var layerFile = System.IO.Path.Combine(Path.GetDirectoryName(dllPath), @"LayersFiles\KILOMETERRIBBON.lyrx");
In Visual Studio project remember to mark your lyrx as Copy to local = true
Dear Gintautas
Thanks for your quick reply. This indeed solves the problem,
System.Reflection.Assembly.GetExecutingAssembly().Location;
"C:\\Users\\udinkr\\AppData\\Local\\ESRI\\ArcGISPro\\AssemblyCache\\{65d5c7d5-cc47-4ef6-b902-74b7f7ec86c7}\\ArcGisImx.dll"
System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
"file:///C:/Users/udinkr/AppData/Local/ESRI/ArcGISPro/AssemblyCache/{65d5c7d5-cc47-4ef6-b902-74b7f7ec86c7}/ArcGisImx.dll"
This folder contains the Install folder of the packages, unzipped.