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 $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 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 $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.

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.

Comments

Name
Comment
jonwillia - 2023-09-05
Onetastic won't let me rotate pdf printouts anymore :/. Keeps saying to use the OneNote native rotate option but OneNote can't rotate printouts. It's the entire reason I got Onetastic in the first place -.-
Christian Treffler - 2023-07-05
I'd like to have the possibility to assign custom hotkeys to Macros. The proposed way via the QAT is quite a poor workaround. Starting with the fact that many Macros have the same Icon in the QAT. And once I add some other features to the QAT the Hotkeys might change.
Collapse all section groups and - 2023-06-23
Could someone write a macro which collapses all section groups and sections in a Notebook?
Would be VERY VERY handy I think

Other Posts

Show all posts