> For the complete documentation index, see [llms.txt](https://www.opal-rt.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.opal-rt.com/docs/hypersim/automation-api-and-scripting/automate-using-testview/test-commands-reference/general/macro.md).

# Macro

## Description

This command calls a Macro during the execution of the TestView script. It can be used to call Python, C-shell or Shell scripts.

<figure><img src="https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-859b7337e1de8654450513d1ae3ea9ab005cb06a%2Fimage%20(1281).png?alt=media" alt=""><figcaption></figcaption></figure>

It makes a local copy of the selected file at the path `[root project directory]/bank/mk/[name of file]` and creates an XML file to keep track of the source folder to the destination folder (one XML per macro).

It cannot send back information to the test sequence directly (e.g. it cannot use MATLAB's processing power). It nevertheless has quite a few uses, such as:

* Pre-processing (e.g. to set up the I/O files)
* Post-processing (e.g. to do data crunching using MATLAB)
* Sending commands to external hardware (e.g. to reset protections between tests)
* Modifying input data for the next test sequence in a batch list (e.g. using TestView's Excel interface)

**Blocking call:** It is sometimes necessary to wait for a macro to end before continuing with the test sequence, especially when interacting with external hardware. Also, when a macro calls a batch file that opens a program and 'blocking call' is enabled, the test sequence pauses until that program is closed.

**Example:**

Using the Macro command, users may not send parameters to a Python script directly. However, they can use a batch file to forward the arguments to the Python script.

Create the following Python script and name the file 'dummy\_python.py'

```python
import sys
print 'Number of arguments:', len(sys.argv), 'arguments.' 
print 'Argument List:', str(sys.argv)
```

Afterward, create a batch file that calls the python script. Name the file 'test\_python.bat'. **Tip:** To create a batch file, create a .txt file and manually change the file extension to .bat.

Change the path on the second line to match the path where your 'dummy\_python.py' file is located.

`@echo off python C:\OPAL-RT\Example\dummy_python.py %1`

Finally, in TestView add the Macro command and point to the batch file.

<figure><img src="https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-101ab7848ca0cbc1c17029c30732fa5ad2a8b9ed%2Fimage%20(1282).png?alt=media" alt=""><figcaption></figcaption></figure>

This will give:

<figure><img src="https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-ecfbc6143c36212ced39737e51dcc7965854215f%2Fimage%20(1283).png?alt=media" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
In the example above, the argument is the literal string 'a'. If 'a' is a variable, then you need to write:

<img src="https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-ecf5bcc4acc9a7db7f82b55589740c2cc410725c%2Fimage%20(1284).png?alt=media" alt="" data-size="original">

Where a = 1 in this example. It will give:

<img src="https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-296ee9bf9e6a563b73a831d3b3257c6fc583279c%2Fimage%20(1285).png?alt=media" alt="" data-size="original">

Remember to use the **Assign** command to initialize the variable before using the **Macro** command.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.opal-rt.com/docs/hypersim/automation-api-and-scripting/automate-using-testview/test-commands-reference/general/macro.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
