Tutorial

Getting Started with Macros

Macro Editor

User Interface

Menus and Toolbar

Editing Macro Statements

Expression Editor

Macro Debugging

How To

Using variables

Finding and modifying objects

Creating new page content

Asking for user input

Storing persistent data

Using binary data

Sorting objects

Macro menus

Bulleted and numbered lists

Sample Macros

Concepts

Expressions

Objects

Properties

Variables

Data Types

Arrays

Functions

Literals

Operators

Comments

Last updated on: March 19, 2023
Also available as a single HTML file

Onetastic Macro Documentation > Concepts > Functions

Functions

Functions in macros are similar to the same concept in other programming languages. They take one or more parameters and return a single value (or no value). They can be used to retrieve objects, manipulate strings, dates, arrays, create and display dialog boxes and control the macro execution.

Following is an example usage of String_Length and GetCurrentPage functions to obtain the length of the title of the current page:

$length = String_Length(GetCurrentPage().name)

Below is the list of all available built-in functions:

User Defined Functions

You can also define your own functions with parameters and return value. You can decide whether the paremeters are passed by reference or by value using the byref keyword. For pass-by-value, a copy of the argument is passed as the parameter. For pass-by-reference, a reference to the argument is passed and the function can modify the caller's argument. Objects are always passed by reference regardless of whether the parameter was decorated by byref or not.

// Function takes a page and adds the images in this page in the byref parameters // It returns a Bool indicating whether it found any images or not Function GetImagesInPage($page, byref $imagesInOutline, byref $imagesOnPage) $images = QueryObjects("Image", $page) ExpandForEach ($image in $images) ExpandIf (GetParentOfType($image, "Page", $parentPage)) Array_PushBack($imagesInOutline, $image) ExpandElse Array_PushBack($imagesOnPage, $image) Return Array_Length($images) > 0
// Get images in the current page $imagesInOutline = Array() $imagesOnPage = Array() ExpandIf (GetImagesInPage(GetCurrentPage(), $imagesInOutline, $imagesOnPage)) // We found some images...

Reference

Statements

For

ForEach

If

Else If

Else

Switch

Case

Default

While

Expression

Comment

Break

Continue

Return

Hierarchy Objects

NotebookRoot

Notebook

SectionGroup

Section

Page

Page Objects

Title

Outline

Table

Column

Row

Cell

Paragraph

Text

Image

EmbeddedFile

Tag

Other Objects

DialogBox

MacroMenu

Window

Functions

Array Functions

Color Functions

Data Store Functions

Date/Time Functions

Dialog Box Functions

Macro Execution Functions

Macro Menu Functions

Object Functions

String Functions

Window Functions