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.

Parents
  • 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

Reply
  • 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

Children
No Data