Generating a file using a script

This article provides an example of a script for generating a file by a template. The template is a document version.

For the script to work, add assemblies:

Elewise.ELMA.Documents 
Elewise.TemplateGenerator.Merged
 
Namespaces:
using EleWise.ELMA.Documents.Managers; 
using EleWise.ELMA.Runtime.Managers; 
using EleWise.ELMA.Services; 
using EleWise.ELMA.Templates;
 
Script:
int id_doc=26; //ID of the template document 
var versionFile = Locator.GetServiceNotNull<IDocumentFileManager>().GetFileByDocumentId(id_doc); 
var file = Locator.GetServiceNotNull<ITemplateFileManager>().CreateFromTemplate(versionFile.Id); 
// Create a generator 
var generator = Locator.GetServiceNotNull<DocumentGeneratorManager>().Create(file.ContentFilePath); 
// Generate a document
generator.Generate(context); 
// Save the generated file
Locator.GetServiceNotNull<IFileManager>().SaveFile(file); 
// Write the result to the variable
context.ResultFile = file;