How to generate analysis report by opening an existing project programmatically via API

Hi,

I want to use Trados API to do project automation. Currently I am familiar with many tasks.

But for analysis report, I have a question. 

Currently, If I run a new project, I know using the following method to generate a report out.

AutomaticTask analyzeTask = project.RunAutomaticTask(targetFiles.GetIds(), AutomaticTaskTemplateIds.AnalyzeFiles);

Guid reportId = analyzeTask.Id;
project.SaveTaskReportAs(reportId, filePath, Sdl.ProjectAutomation.Core.ReportFormat.Excel);

But I want just to open an existing project and only want to generate the analysis report, how to to do that, I don't know how to get the report ID without running the analysis (the exisitng project has run the analysis task).

I am using two versions, Trados 2019 and Trados 2024, both version do not have such API doc about this part.

Thanks,

Parents
  • Hi  , the API doesn't expose a direct way to programmatically extract the existing analysis task and its report without re-running the analysis.  You can however recover the taskId from the generated analysis.xml reports that are in the project folder `Reports\`.  

    Example:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    using System;
    using System.Xml;
    public static class ReportXmlHandler
    {
    public static string GetTaskIdFromReport(string filePath)
    {
    if (string.IsNullOrEmpty(filePath))
    throw new ArgumentException("filePath cannot be null or empty.", nameof(filePath));
    try
    {
    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.Load(filePath);
    XmlNode taskInfoNode = xmlDoc.SelectSingleNode("//task/taskInfo");
    return taskInfoNode?.Attributes?["taskId"]?.Value;
    }
    catch (Exception ex)
    {
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Hi  ,

    Thank you for reply. I am wondering after getting the taskId, what I should do to get the analysis task or report, do you have more suggestions?

Reply Children