ProjectAutomation API - TargetLanguageStatistics is null

Hi there,

I am currently writing a Studio plugin that will export an overview of Revisions (for LQA system).

Most things work fine, i.e. revisions and comments are exported and project information such as source and target language as well as word count of the revised document get exported, too. What I cannot get though is the total word count of all files for that target language.

Here is how I try to achieve this:

var stats = project.GetProjectStatistics();
var targetlang = document.ActiveFile.Language;
var tstats = stats.TargetLanguageStatistics.FirstOrDefault(t => t.TargetLanguage == targetlang);

try
{
	((Excel.Range)lqc.Cells[7, 5]).Formula = tstats.ConfirmationStatistics.Total.Words.ToString();
}
catch (Exception ex)
{
	using (var sw = new StreamWriter(errorlog))
	{
		sw.WriteLine(ex.Message);
		if (tstats == null)
		{
			sw.WriteLine("tstats is null");
			sw.WriteLine(targetlang.DisplayName);
		}
	}
}

 Alas, tstats is always null.

This is a simple English => German project, manually created, fully prepared including analysis. I also ran an additional batch task Count words and Analyse to be on the safe side. Still, the error log says:

Object reference not set to an instance of an object.
tstats is null
German (Germany)

So the target language is clearly properly set, yet there do not seem to be any TargetLanguageStatistics for the target language.

Can anyone tell me what I am doing wrong?

Thanks!
Andreas

Parents
  • I still don't get it.

    According to this: http://producthelp.sdl.com/SDK/ProjectAutomationApi/3.0/html/1d1bfee5-0d11-4a7f-9c55-5381902dfa4a.htm it should work!

    I have modified my code a little to make sure an automatic task TranslationCount is run before I access the statistics:

    var stats = project.GetProjectStatistics();
    
    var fileIds = project.GetTargetLanguageFiles(targetlang).GetIds();
    AutomaticTask task = project.RunAutomaticTask(fileIds, AutomaticTaskTemplateIds.TranslationCount);
    while (!(task.Status == TaskStatus.Completed || task.Status == TaskStatus.Failed))
    {
    	Thread.Sleep(50);
    }
    try
    {
    	var report = task.Reports.FirstOrDefault();
    	if (report != null)
    	{
    		var AllTargetStats = stats.TargetLanguageStatistics;
    		for (var i = 0; i < AllTargetStats.Length; i++)
    		{
    			var tstats = AllTargetStats[i];
    			if (tstats.TargetLanguage == targetlang)
    			{
    				using (var sw = new StreamWriter(errorlog)
    				{
    					sw.WriteLine("tstats is set!");
    				}
    			}
    		}
    
    		//var repxml = repPath;
    		//project.SaveTaskReportAs(report.Id, repxml, ReportFormat.Xml);
    		//var xml = new XmlDocument();
    		//xml.Load(repxml);
    		////totalwords = xml.SelectSingleNode("//batchTotal/total").Attributes.GetNamedItem("words").Value;
    		//totalwords = tstats.ConfirmationStatistics.Total.Words.ToString();
    	}
    }
    catch
    {
    }

     Still, despite running the TranslationCount task on the target files, I get no TargetLanguageStatistics for that language!

    As you can see, I have also used a workaround by saving the task report as xml and reading the result from there. This works. But I am now hell-bent on at least learning why the darn thing does not work directly.

  • Hi Andreas,

    I believe the problem is how you are comparing using ==, i.e. its doing a reference comparison and not a value comparison.

    Sdl.Core.Globalization.Language is a class and does not contain a == overload.

    Try the following code instead:

    tstats.TargetLanguage.Equals(targetlang);
Reply Children