Select to view content in your preferred language

Access Project-File (.aprx) using the SDK

1340
1
Jump to solution
11-17-2021 11:34 PM
Kai_DA
by
Emerging Contributor

Hey,

I am currently looking into the possibilty of accessing a ArcGIS Pro Project from the "outside" using the ArcGIS Pro SDK. 

What I mean by that is that is that I don't want to access the "current" project using an AddIn, but instead use the Core-Assembly to access the content of a project from the outside, similar to what arcpy does by using soemthing like this:

aprx = arcpy.mp.ArcGISProject(r"Path_to_my_project\project.aprx")

 

During my own research I could not find anything about it, so I wanted to make sure that its not possible by posting my question here.

 

Many thanks in advance!

0 Kudos
1 Solution

Accepted Solutions
KirkKuykendall1
Frequent Contributor

The aprx file is a zip file containing xml which can be deserialized as CIM objects.  Last I checked this is also "core" in the sense that it can be run with dotnet core (apparently no license initialization required).

private static void Test()
{
    string aprxFile = @"D:\ArcPro_Projects\Naperville\Naperville.aprx";
    using (ZipArchive archive = System.IO.Compression.ZipFile.OpenRead(aprxFile))
    {
        foreach (var entry in archive.Entries
            .Where(e => !e.FullName.StartsWith("Metadata/"))
            .Where(e => e.FullName.EndsWith(".xml")))
        {
            try
            {
                using (var strm = new StreamReader(entry.Open()))
                {
                    var xml = strm.ReadToEnd();
                    var obj = CIMObject.FromXml(xml);
                    Debug.Print($"type: {obj}");
                }
            }
            catch(Exception ex)
            {
                Debug.Print($"error {entry.FullName} : {ex.Message}");
            }
        }
    }
}

View solution in original post

1 Reply
KirkKuykendall1
Frequent Contributor

The aprx file is a zip file containing xml which can be deserialized as CIM objects.  Last I checked this is also "core" in the sense that it can be run with dotnet core (apparently no license initialization required).

private static void Test()
{
    string aprxFile = @"D:\ArcPro_Projects\Naperville\Naperville.aprx";
    using (ZipArchive archive = System.IO.Compression.ZipFile.OpenRead(aprxFile))
    {
        foreach (var entry in archive.Entries
            .Where(e => !e.FullName.StartsWith("Metadata/"))
            .Where(e => e.FullName.EndsWith(".xml")))
        {
            try
            {
                using (var strm = new StreamReader(entry.Open()))
                {
                    var xml = strm.ReadToEnd();
                    var obj = CIMObject.FromXml(xml);
                    Debug.Print($"type: {obj}");
                }
            }
            catch(Exception ex)
            {
                Debug.Print($"error {entry.FullName} : {ex.Message}");
            }
        }
    }
}