Skip to content

Commit

Permalink
Added documentation on creating macros (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlonsk authored Jan 15, 2024
1 parent 67ab7b5 commit 2bff92f
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 53 additions & 3 deletions te3/tutorials/creating-macros.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
uid: creating-macros
title: Creating macros
author: Daniel Otykier
updated: 2021-09-08
author: Morten Lønskov
updated: 2023-12-07
applies_to:
editions:
- edition: Desktop
Expand All @@ -11,4 +11,54 @@ applies_to:
---
# (Tutorial) Creating macros

(WIP)
Macros are C# scripts that have been saved in Tabular Editor to be easily reused across semantic models.
Saving a script as a Macro will allow that macro to be used when right clicking on the objects in the TOM Explorer making it simple to apply the script to your model.

## Creating a Macro

The first step in creating a Macro is to create and test a C# script.

> [!TIP]
>One easy way to get started with C# scripting is to use the built in record function that lets you record the actions you take in the TOM Explorer.
>This way you can see how to interact with the different model objects and create reusable scripts.
>Another way is to reuse existing scripts such as those in our [script library](xref:csharp-script-library).
>In this tutorial we use the script [Format Numeric Measures](xref:script-format-numeric-measures) to showcase the Macro functionality.
Once the script works according requirements the script can be saved using the toolbar button "Save as Macro" which will open the "Save Macro" window.

![Macro Create infobox](~/images/features/macros/macro_tutorial_create_infobox.png)

The "Save Macro" window allows three options:
1. Macro Name: Give the Macro a name and use backslash "\" to create folder path for the macro (See bellow)
2. Provide a tooltip for the Macro to remember what it does in detail
3. Select a context where the Macro should be available.

![Macro Save infobox](~/images/features/macros/macro_tutorial_save_window.png)

In the above example the Macro will be saved in a folder called Formatting\Beginner and the script is called "Format Numeric Measures". It will be saved in the context of measures.

### Macro Context
Macros are saved in a "valid context" that determines which objects in the model the script can be applied to.

This Macro can then be used when Right Clicking on a measure in the TOM Explorer. The context given while saving the Macro determines which objects will show the Macro when right clicking on that object.

Tabular Editor will suggest a context based on the script that is being saved.

![Macro Menu Shortcut](~/images/features/macros/macro_tutorial_menu_shortcut.png)

## Edit a Macro

A macro can be opened by double clicking it in the Macro pane and after editing the C# script saved using _Ctrl + S_ or the Edit Macro button.

![Macro Edit Infobox](~/images/features/macros/macro_tutorial_edit_infobox.png)


## Macro JSON file

Macros are stored in the %LocalAppFolder%/TabularEditor3 as a JSON file called MacroActions.json. For more information on file types in Tabular Editor please see [Supported File Types](xref:supported-files#macroactionsjson)

## Macro file example

An example of a MacroActions.JSON file can be found here. It contains several of the C# scripts from our script library: [Download example MacroActions File](https://raw.githubusercontent.com/TabularEditor/TabularEditorDocs/main/assets/file-types/MacroActions.json)


0 comments on commit 2bff92f

Please sign in to comment.