Inserting Images and Embedded Files via Macros

May 06, 2023

With the latest update to Onetastic, you can now insert images and embedded files with macros. OneNote pages can contain external files in the form of images and embedded files. 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 $ = $

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 Macro Editor 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 $ = 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.

Due to security considerations, macros with binary data currently cannot be uploaded to Macroland. You can still export and import macros to share between your computers or within your organization. Binary store is available to users with Onetastic Dev license.


XRumerTest - 2023-06-02
Hello. And Bye.
TX.Aggie.TPM - 2023-05-15
It would be great if someone wrote a macro to remove the zoom text inserted into Outlook meetings when they are transferred to OneNote.

It's a big block of text that is a waste at several levels.  At the least, remove everything but the meeting ID/password.  Who needs to see the list of phone numbers in effect that day?
Onetastic ★ - 2023-05-14
Sparks In Texas: Try the new update published today

Other Posts

Show all posts