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 > How To > Using binary data

Using binary data

OneNote pages can contain external files in the form of Images and EmbeddedFiles. These objects store the actual data for the image or the embedded file in their data properties. You can duplicate an image by copying the data property:

// Find an existing image on a page $page = GetCurrentPage() $existingImage = $page.images[0] // Create a new image $newImage = InsertObject($page, "Image", -1) // Copy the binary data $newImage.data = $existingImage.data

This macro will create a second image on the same page and copy the existing image data to it, creating a copy of the image.

Binary Store

In order to create new images or embedded files, the data property must be set to a valid binary data. While macros can copy such data from existing content, as seen above, they can also store such data and use it to create new content. Binary store is where macros can store files to be used to create images and embedded files.

To access binary store for a macro you can go to Storage > Edit Binary Storage on the menu. This will display the Binary Store window:

Binary Store

You can use Add Files button to choose one or more files to add to the binary store. After adding files, you can rename them or remove any files you don't need:

Binary Store with Files

Using files from Binary Store

You can use files from binary store via the BinaryStore_Read function. Pass the name of the file in the binary store to access it:

$page = GetCurrentPage() // Create a new image $newImage = InsertObject($page, "Image", -1) // Set the binary data $newImage.data = BinaryStore_Read("flower.png")

This will create a new image using the flower.png file in the binary store. Binary store is per macro. You cannot access files from binary store of one macro from another macro. If you need to use the same files, simply add them to each macro.

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