Tutorial

Getting Started with Macros

Macro Editor

User Interface

Menus and Toolbar

Editing Macros

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: September 02, 2024
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 GetImagesInPage($page, byref $imagesInOutline, byref $imagesOnPage) // 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 $images = QueryObjects("Image", $page) foreach ($image in $images) if (GetParentOfType($image, "Page", $parentPage)) Array_PushBack($imagesInOutline, $image) else Array_PushBack($imagesOnPage, $image) return Array_Length($images) > 0
// Get images in the current page $imagesInOutline = Array() $imagesOnPage = Array() if (GetImagesInPage(GetCurrentPage(), $imagesInOutline, $imagesOnPage)) // We found some images...

Reference

Statements

Hierarchy Objects

Page Objects

Other Objects

Functions

Array Functions

Color Functions

Data Store Functions

Date/Time Functions

Dialog Box Functions

Macro Execution Functions

Macro Menu Functions

Object Functions

Special Functions

String Functions

Window Functions