Hi everyone,
I have converted an ArcObjects SDK .NET application written in C# for creating PDF maps to an ArcGIS Pro add-in using the ArcGIS Pro SDK. Everything runs fine from within ArcGIS Pro but now I want to convert it to a standalone complied exe as the original is so I can run it from Windows Task Scheduler.
From my research, I understand that await QueuedTask.Run is only needed inside of Pro so I have been slowly removing these one function at a time in the order that each function runs.
Things work until I get to the function below which is supposed to open an aprx that I use as a template (has layout that I manipulate, layers loaded, etc.) and return a Project object which is used later in the code to retrieve a Map and a Layout.
Hi,
Project.OpenAsync returns Task<Project>. So, to assign result of Project.OpenAsync to Project variable, you need to use await before Project.OpenAsync. Your method could look like code below:
public static async Task<Project> GetProject()
{
try
{
string aprxFile = PATH_Aprx_template + "exhibit_map.aprx";
// Open the project
Project project = await Project.OpenAsync(aprxFile);
// Check if the project is null (failed to open)
if (project == null)
{
Console.WriteLine("Failed to open the project.");
return null;
}
return project;
}
catch (Exception ex)
{
Console.WriteLine($"Error in GetProject: {ex.Message}");
return null;
}
}
Thanks for your help, I really appreciate it. I will try this on Monday and post back.
Hi,
are you sure this line:
Project project = await Project.OpenAsync(aprxFile);
will work? Carlos already used something similar :
Project project = Project.OpenAsync(aprxFile).Result;
without succes. I know with Result it would block until the task is completed, but in his case it seems to me he needs to wait for the result anyway.
Hi guys, thanks for the replies. Unfortunately, the suggestions did not work. Below is the original function that works fine in my add-in but now that I am converting the code to a console standalone application, the await QueuedTask.Run no longer applies. So I guess I need a different way to get a reference to the project.
Sorry @CarlosPiccirillo2 .
Project class belongs to ArcGIS.Desktop.Core workspace which is not accessible from CoreHost application. ArcGIS.CoreHost and ArcGIS.Core assemblies are available from Corehost application only. More information here.
Thanks for the clarification. Do you know have I can get a reference to a Project (aprx) using ArcGIS.CoreHost or ArcGIS.Core?
You could try to call python script with your workflow from CoreHost application or execute python script directly. We have similar situation with geoprocessing in CoreHost application. There is no way to call geoprocessing tool directly, but you can call it from python.
The entire application is quite complex which is why I was trying to avoid going the Python route but It's starting to look like I will have to re-write the entire application in Python which I was hoping to avoid. Only have a year of experience in Python but over 15 years in C# which is why I ported over the old ArcMap (ArcObjects) code using C#.