Class ScriptHelper
Contains various extension methods which are commonly used in scripts
Inherited Members
Namespace: TabularEditor.Shared.Scripting
Assembly: TabularEditor3.Shared.dll
Syntax
public static class ScriptHelper
Properties
WaitFormVisible
Toggle the "Please wait" spinner on/off. Useful if you want to display custom dialogs / UI to the end user.
Declaration
public static bool WaitFormVisible { get; set; }
Property Value
Type | Description |
---|---|
bool |
Remarks
Built-in script UI such as the TabularEditor.Shared.Scripting.ScriptHelper.Info(System.String,System.Int32) and SelectMeasure(IEnumerable<Measure>, Measure, string) functionality will automatically hide the "Please wait" spinner.
Methods
CustomAction(IEnumerable<ITabularNamedObject>, int)
Run a macro on a selection of objects. Alias for Macro(IEnumerable<ITabularNamedObject>, int)
Declaration
public static void CustomAction(this IEnumerable<ITabularNamedObject> selection, int macroId)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<ITabularNamedObject> | selection | The object selection on which the macro should run. |
int | macroId | Id of the macro |
CustomAction(IEnumerable<ITabularNamedObject>, string)
Run a macro on a selection of objects. Alias for Macro(IEnumerable<ITabularNamedObject>, string)
Declaration
public static void CustomAction(this IEnumerable<ITabularNamedObject> selection, string macroName)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<ITabularNamedObject> | selection | The object selection on which the macro should run. |
string | macroName | Name of the macro. Use fully path of macro in case of ambiguity. |
CustomAction(ITabularNamedObject, int)
Run a macro on an object. Alias for Macro(ITabularNamedObject, int)
Declaration
public static void CustomAction(this ITabularNamedObject selection, int macroId)
Parameters
Type | Name | Description |
---|---|---|
ITabularNamedObject | selection | The object on which the macro should be run. |
int | macroId | Id of the macro |
CustomAction(ITabularNamedObject, string)
Run a macro on an object. Alias for Macro(ITabularNamedObject, string)
Declaration
public static void CustomAction(this ITabularNamedObject selection, string macroName)
Parameters
Type | Name | Description |
---|---|---|
ITabularNamedObject | selection | The object on which the macro should be run. |
string | macroName | Name of the macro. Use fully path of macro in case of ambiguity. |
ExportProperties(IEnumerable<ITabularNamedObject>, string)
Export properties of the specified set of objects to a TSV (tab-separated) string. Use ImportProperties(string) to import properties from a TSV string.
Declaration
public static string ExportProperties(this IEnumerable<ITabularNamedObject> objects, string properties = "Name,Description,SourceColumn,Expression,FormatString,DataType")
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<ITabularNamedObject> | objects | Set of objects whose properties should be serialized |
string | properties | (Optional) Comma-separated list of properties to export. If omitted, a default set of properties are exported. |
Returns
Type | Description |
---|---|
string |
FormatDax(IEnumerable<IDaxDependantObject>, bool?, bool?)
Formats the DAX on all the specified objects.
Declaration
public static void FormatDax(this IEnumerable<IDaxDependantObject> objects, bool? shortFormat = null, bool? skipSpaceAfterFunctionName = null)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IDaxDependantObject> | objects | The list of objects to be formatted |
bool? | shortFormat | TRUE to use short DAX format, FALSE otherwise, null to use current Tabular Editor settings |
bool? | skipSpaceAfterFunctionName | FALSE to add a space after function names, TRUE otherwise, null to use current Tabular Editor settings |
FormatDax(IDaxDependantObject)
Flags this object for DAX expression formatting at the end of script execution or when TabularEditor.Shared.Scripting.ScriptHelper.CallDaxFormatter(System.Nullable{System.Boolean},System.Nullable{System.Boolean}) is called.
Declaration
public static void FormatDax(this IDaxDependantObject obj)
Parameters
Type | Name | Description |
---|---|---|
IDaxDependantObject | obj | The object whose DAX expression needs to be formatted |
GetCardinality(Column)
Gets the cardinality (unique value count) of the specified column, assuming VertiPaq Analyzer stats have been collected. Call CollectVertiPaqAnalyzerStats() to collect VertiPaq Analyzer stats.
Declaration
public static long GetCardinality(this Column column)
Parameters
Type | Name | Description |
---|---|---|
Column | column |
Returns
Type | Description |
---|---|
long |
GetCardinality(Table)
Gets the cardinality (row count) of the specified table, assuming VertiPaq Analyzer stats have been collected. Call CollectVertiPaqAnalyzerStats() to collect VertiPaq Analyzer stats.
Declaration
public static long GetCardinality(this Table table)
Parameters
Type | Name | Description |
---|---|---|
Table | table |
Returns
Type | Description |
---|---|
long |
GetTotalSize(Column)
Gets the total size (in bytes) of the specified column, assuming VertiPaq Analyzer stats have been collected. Call CollectVertiPaqAnalyzerStats() to collect VertiPaq Analyzer stats.
Declaration
public static long GetTotalSize(this Column column)
Parameters
Type | Name | Description |
---|---|---|
Column | column |
Returns
Type | Description |
---|---|
long |
GetTotalSize(Table)
Gets the total size (in bytes) of the specified table, assuming VertiPaq Analyzer stats have been collected. Call CollectVertiPaqAnalyzerStats() to collect VertiPaq Analyzer stats.
Declaration
public static long GetTotalSize(this Table table)
Parameters
Type | Name | Description |
---|---|---|
Table | table |
Returns
Type | Description |
---|---|
long |
Macro(IEnumerable<ITabularNamedObject>, int)
Run a macro on a selection of objects.
Declaration
public static void Macro(this IEnumerable<ITabularNamedObject> selection, int macroId)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<ITabularNamedObject> | selection | The object selection on which the macro should run. |
int | macroId | Id of the macro |
Macro(IEnumerable<ITabularNamedObject>, string)
Run a macro on a selection of objects.
Declaration
public static void Macro(this IEnumerable<ITabularNamedObject> selection, string macroName)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<ITabularNamedObject> | selection | The object selection on which the macro should run. |
string | macroName | Name of the macro. Use fully path of macro in case of ambiguity. |
Macro(ITabularNamedObject, int)
Run a macro on an object.
Declaration
public static void Macro(this ITabularNamedObject selection, int macroId)
Parameters
Type | Name | Description |
---|---|---|
ITabularNamedObject | selection | The object on which the macro should be run. |
int | macroId | Id of the macro |
Macro(ITabularNamedObject, string)
Run a macro on an object.
Declaration
public static void Macro(this ITabularNamedObject selection, string macroName)
Parameters
Type | Name | Description |
---|---|---|
ITabularNamedObject | selection | The object on which the macro should be run. |
string | macroName | Name of the macro. Use fully path of macro in case of ambiguity. |
Output(object)
Displays detailed information about the specified object or collection of objects in a popup dialog. When executed through the UI, the user has an option to ignore additional popups. When the script is running in the CLI, the information is written to the console.
Declaration
public static void Output(this object value)
Parameters
Type | Name | Description |
---|---|---|
object | value |
SelectColumn(IEnumerable<Column>, Column, string)
Displays a dialog that allows the user to select a column from the specified collection.
Declaration
public static Column SelectColumn(this IEnumerable<Column> columns, Column preselect = null, string label = "Select column:")
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<Column> | columns | A list of columns to be shown to the user |
Column | preselect | (Optional) A column from the list of columns, which is preselected when the dialog is shown |
string | label | (Optional) A label to be shown within the dialog |
Returns
Type | Description |
---|---|
Column | The selected column or null if the user cancels out of the dialog |
SelectColumn(Table, Column, string)
Displays a dialog that allows the user to select a column from the specified table.
Declaration
public static Column SelectColumn(this Table table, Column preselect = null, string label = "Select column:")
Parameters
Type | Name | Description |
---|---|---|
Table | table | The table from which the user should select a column |
Column | preselect | (Optional) A column from the list of columns, which is preselected when the dialog is shown |
string | label | (Optional) A label to be shown within the dialog |
Returns
Type | Description |
---|---|
Column | The selected column or null if the user cancels out of the dialog |
SelectMeasure(IEnumerable<Measure>, Measure, string)
Displays a dialog that allows the user to select a measure from the specified list of measures.
Declaration
public static Measure SelectMeasure(this IEnumerable<Measure> measures, Measure preselect = null, string label = "Select measure:")
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<Measure> | measures | A list of measures to be shown to the user |
Measure | preselect | (Optional) A measure from the list of measures, which is preselected when the dialog is shown |
string | label | (Optional) A label to be shown within the dialog |
Returns
Type | Description |
---|---|
Measure | The selected measure or null if the user cancels out of the dialog |
SelectMeasure(Model, Measure, string)
Displays a dialog that allows the user to select a measure from the model.
Declaration
public static Measure SelectMeasure(this Model model, Measure preselect = null, string label = "Select measure:")
Parameters
Type | Name | Description |
---|---|---|
Model | model | The model from which a measure should be selected by the user |
Measure | preselect | (Optional) A measure from the model, which is preselected when the dialog is shown |
string | label | (Optional) A label to be shown within the dialog |
Returns
Type | Description |
---|---|
Measure | The selected measure or null if the user cancels out of the dialog |
SelectMeasure(Table, Measure, string)
Displays a dialog that allows the user to select a measure from the specified table.
Declaration
public static Measure SelectMeasure(this Table table, Measure preselect = null, string label = "Select measure:")
Parameters
Type | Name | Description |
---|---|---|
Table | table | A table containing the measures that will be shown to the user |
Measure | preselect | (Optional) A measure from the table, which is preselected when the dialog is shown |
string | label | (Optional) A label to be shown within the dialog |
Returns
Type | Description |
---|---|
Measure | The selected measure or null if the user cancels out of the dialog |
SelectObject<T>(IEnumerable<T>, T, string)
Displays a dialog that allows the user to select a model object from a list of objects.
Declaration
public static T SelectObject<T>(this IEnumerable<T> objects, T preselect = null, string label = "Select object:") where T : TabularNamedObject
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | objects | A list of objects to be shown to the user |
T | preselect | (Optional) An object from the list, which is preselected when the dialog is shown |
string | label | (Optional) A label to be shown within the dialog |
Returns
Type | Description |
---|---|
T | The selected object or null if the user cancels out of the dialog |
Type Parameters
Name | Description |
---|---|
T | The type of objects shown to the user |
SelectObjects<T>(IEnumerable<T>, IEnumerable<T>, string)
Displays a dialog that allows the user to select one or more model objects from a list of objects.
Declaration
public static IList<T> SelectObjects<T>(this IEnumerable<T> objects, IEnumerable<T> preselect = null, string label = "Select object(s):") where T : TabularNamedObject
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | objects | A list of objects to be shown to the user |
IEnumerable<T> | preselect | (Optional) A list of objects which are preselected when the dialog is shown |
string | label | (Optional) A label to be shown within the dialog |
Returns
Type | Description |
---|---|
IList<T> | The selected object(s) or null if the user cancels out of the dialog |
Type Parameters
Name | Description |
---|---|
T | The type of objects shown to the user |
SelectTable(IEnumerable<Table>, Table, string)
Displays a dialog that allows the user to select a table from the specified list of tables.
Declaration
public static Table SelectTable(this IEnumerable<Table> tables, Table preselect = null, string label = "Select table:")
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<Table> | tables | A list of tables to be shown to the user |
Table | preselect | (Optional) A table from the list of tables, which is preselected when the dialog is shown |
string | label | (Optional) A label to be shown within the dialog |
Returns
Type | Description |
---|---|
Table | The selected table or null if the user cancels out of the dialog |
SelectTable(Model, Table, string)
Displays a dialog that allows the user to select a table from the model.
Declaration
public static Table SelectTable(this Model model, Table preselect = null, string label = "Select table:")
Parameters
Type | Name | Description |
---|---|---|
Model | model | The model from which the user should select a table |
Table | preselect | (Optional) A table which is preselected when the dialog is shown |
string | label | (Optional) A label to be shown within the dialog |
Returns
Type | Description |
---|---|
Table | The selected table or null if the user cancels out of the dialog |
SuspendWaitForm(Action)
Hides the "Please wait" spinner while performing the specified action. Useful if the action displays custom dialogs / UI to the end user.
Declaration
public static void SuspendWaitForm(Action action)
Parameters
Type | Name | Description |
---|---|---|
Action | action |
Remarks
Built-in script UI such as the TabularEditor.Shared.Scripting.ScriptHelper.Info(System.String,System.Int32) and SelectMeasure(IEnumerable<Measure>, Measure, string) functionality will automatically hide the "Please wait" spinner.
SuspendWaitForm<T>(Func<T>)
Hides the "Please wait" spinner while performing the specified action. Useful if the action displays custom dialogs / UI to the end user.
Declaration
public static T SuspendWaitForm<T>(Func<T> action)
Parameters
Type | Name | Description |
---|---|---|
Func<T> | action |
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T |
Remarks
Built-in script UI such as the TabularEditor.Shared.Scripting.ScriptHelper.Info(System.String,System.Int32) and SelectMeasure(IEnumerable<Measure>, Measure, string) functionality will automatically hide the "Please wait" spinner.