2021-10-17 18:26:00 +02:00
|
|
|
---
|
2022-10-12 21:52:47 +02:00
|
|
|
title: Macro methods
|
|
|
|
order: 120
|
2021-10-17 18:26:00 +02:00
|
|
|
---
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-10-12 21:52:47 +02:00
|
|
|
FreeSewing plugins can provide macros, which is a way to automate multiple
|
|
|
|
steps into a single command.
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-10-12 21:52:47 +02:00
|
|
|
## Signature
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-10-12 21:52:47 +02:00
|
|
|
To provide one or more macros, your plugin should have a `macros` property that
|
|
|
|
is an object where the keys are the macro name, and the value holds a method to
|
|
|
|
run when the macro is executed.
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-10-12 21:52:47 +02:00
|
|
|
```mjs
|
|
|
|
const myPlugin = {
|
|
|
|
name: 'example',
|
|
|
|
version: '0.0.1',
|
2021-08-25 16:09:31 +02:00
|
|
|
macros: {
|
2022-10-12 21:52:47 +02:00
|
|
|
example: function(so, { log }) {
|
|
|
|
log.info('Running the example macro')
|
|
|
|
}
|
|
|
|
}
|
2021-08-25 16:09:31 +02:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2022-10-12 21:52:47 +02:00
|
|
|
## Arguments
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-10-12 21:52:47 +02:00
|
|
|
All macros receive two arguments:
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-10-12 21:52:47 +02:00
|
|
|
- `so`: A plain object holding configuration object passed to the macro
|
2022-12-25 21:13:48 -08:00
|
|
|
- `props`: The same object as passed to the [`Part.draft()`](/reference/api/part/draft) method that you can destructure
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
<Note>
|
|
|
|
###### Macros take only 1 argument
|
|
|
|
|
|
|
|
When writing a macro, keep in mind that all information that needs to be passed
|
|
|
|
to a macro needs to be contained in a single argument.
|
|
|
|
|
|
|
|
Typically, you use a single plain object to configure the macro.
|
|
|
|
|
|
|
|
</Note>
|
2022-10-12 21:52:47 +02:00
|
|
|
|
|
|
|
## Return value
|
|
|
|
|
|
|
|
Macros do not need to return anything. If they do, it will be ignored.
|