-
Notifications
You must be signed in to change notification settings - Fork 6
Help Needed: C# Scripting from .dll #844
Description
Hi Team,
I have an issue when trying to create a custom dll to call reusable code.
I want to be able to create methods where I can add measure to folders, create hierarchies, format columns etc...
For that I have used some help from bernatagulloesbrina on his blog posts and other ressources on internet as well as this issue section repository here.
When I use the class in Tabular editor (with some updating to catter for the model and to be able the class, etc...). It works. But when I am using the dll as reference to use the cade I get an error. Error happens when trying to add a second column to a hierrachy I have just created.
The dll is quite simple:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TabularEditor.TOMWrapper;
using TabularEditor.Scripting;
using static TabularEditor.Scripting.ScriptHelper;
using System.Reflection;
namespace TE_Helper
{
public class TE_Wrapper
{ //public static
public Model Model; // Define the model that is going to be used.
TabularEditor.UI.UITreeSelection Selected; // To be able to use SelectTable() or SelectColumn(), etc...
public void AddColumnToHierarch(string tableName, string HierarchyName, string ColumnName)
{
// to be used by calling function: AddColumnToHierarch(tableName, HierarchyName, ColumnName);
// Check if hierarchy exists
if (!Model.AllHierarchies.Any(h => h.Name == HierarchyName))
{
var h = Model.Tables[tableName].AddHierarchy(HierarchyName);
}
// Check if column exists and if not already in hierarchy
if (Model.Tables[tableName].Columns.Any(t => t.Name == ColumnName) && !Model.Tables[tableName].Hierarchies[HierarchyName].GetChildren().Any(t => t.Name == ColumnName))
{
Model.Tables[tableName].Hierarchies[HierarchyName].AddLevel(ColumnName);
}
}
}
}
and the code I use to call the function in Tabular Editor is as followed:
#r "C:\Users\xxxxxxxxxx\AppData\Local\TabularEditor3\TE_Helper.dll"
using TE_Helper;
var tableName = "Date";
var MyHelpersScripts = new TE_Helper.TE_Wrapper();
MyHelpersScripts.Model = Model;
// Creation Hierarchy
var HierarchyName = "__Calendar Year Hierarchy";
MyHelpersScripts.AddColumnToHierarch(tableName, HierarchyName, "Calendar Year");
MyHelpersScripts.AddColumnToHierarch(tableName, HierarchyName, "Calendar Quarter");
and here is the error message.

would you be able to help me please? I assume I am not referencing properly tabular editor dll but I can't figure it out myself.
Thank you