Remove programmatically all termbases from a project

Dear users,

In SDL Studio 2014, I need to implement a function which removes all termbases from a project.

I tried to overwrite the current List with an empty one. 

TermbaseConfiguration termbaseConfig = project.GetTermbaseConfiguration();

int tbCount = termbaseConfig.Termbases.Count;

if (tbCount > 0)

{

   termbaseConfig.Termbases = new List<Termbase>();

 

   project.UpdateTermbaseConfiguration(termbaseConfig);

}

 

However, I get the runtime argument exception "No termbases have been specified." when the UpdateTermbaseConfiguration method is invoked. It seems that the configuration requires at least one termbase to work properly.

Any suggestion would be appreciated.

  • Looking at project file of a project without termbase configured I deduce that it needs to have at least some basic termbase options configured:

      <TermbaseConfiguration>
        <LanguageIndexMappings>
          <Language>en-US</Language>
        </LanguageIndexMappings>
        <LanguageIndexMappings>
          <Language>de-DE</Language>
        </LanguageIndexMappings>
        <LanguageIndexMappings>
          <Language>fr-FR</Language>
        </LanguageIndexMappings>
        <RecognitionOptions>
          <ShowWithNoAvailableTranslation>false</ShowWithNoAvailableTranslation>
          <MinimumMatchValue>70</MinimumMatchValue>
          <SearchDepth>200</SearchDepth>
          <SearchOrder>Parallel</SearchOrder>
        </RecognitionOptions>
      </TermbaseConfiguration>

  • Dear Evzen, thank you for your remark.
    The TermbaseConfiguration object has indeed two properties "LanguageIndexes" and "TermRecognitionOptions" which appear to be serialized in your snippet.
    In my code, though, I do not access (or modify) them, so they should remain as they were before.

    Besides, I have tested resetting them too (like I do for the Termbases property), but this does not solve the issue either.
  • My point was that I would not really wonder if after resetting the Termbases property the entire TermbaseConfiguration "gets reset completely" somehow.

    But that is apparently not the issue here.
    My quick test in PowerShell shows that even loading the termbase configuration from a project (created manually in Studio without termbase) and calling the UpdateTermbaseConfiguration without any changes throws that exception too :-O

    Hmmm... yet another discovery of weird things happening in Studio outside of API?

  • Hi Dino

    Instead of reusing the current termbase configuration, try creating a new one and setting that.

    TermbaseConfiguration termbaseConfig = project.GetTermbaseConfiguration();

    int tbCount = termbaseConfig.Termbases.Count;

    if (tbCount > 0)

    {

       TermbaseConfiguration emptyTermbaseConfig = new TermbaseConfiguration();

       project.UpdateTermbaseConfiguration(emptyTermbaseConfig);

    }

  • I use the API to add termbases but I have not come across any option to delete one.

    So although it is kind of a hack I would simply remove the "Termbases" node from the TermbaseConfiguration node in the project xml.

    For that you need to unload the project first, make the change, then re-load the updated file:

    var controller = SdlTradosStudio.Application.GetController<ProjectsController>();
    var project = controller.CurrentProject;
    var pPath = project.FilePath;
    controller.Close(project);

    var pfad = Path.GetDirectoryName(pPath);
    var projectXML = new XmlDocument();
    projectXML.Load(pPath);

    var tBases = projectXML.SelectSingleNode("/Project/TermbaseConfiguration/Termbases");
    tBases.ParentNode.RemoveChild(tBases);
    projectXML.Save(pPath);
    project = new FileBasedProject(pPath);
    controller.Open(project);

     

    Would that be OK?

     

    Cheers,

    Andreas