Get AI summaries of any video or article — Sign up free
Improve knowledge discovery by reusing icons. Create an image library with Excalidraw Script Engine thumbnail

Improve knowledge discovery by reusing icons. Create an image library with Excalidraw Script Engine

5 min read

Based on Zsolt's Visual Personal Knowledge Management's video on YouTube. If you like this content, support the original creators by watching, liking and subscribing to their content.

TL;DR

Use a strict icon filename convention starting with “icon,” followed by keywords and a dashed source segment to make icons both searchable and reusable.

Briefing

A practical way to reuse icons inside Excalidraw drawings hinges less on finding good artwork and more on treating icon files like structured data. By enforcing a naming convention (including keywords and the image source) and then auto-building an icon grid from those files, knowledge workers can turn a personal vault into a searchable, copy-pasteable image library—while also strengthening cross-document connections.

The workflow starts with file naming. Icons are stored as files whose names begin with a consistent prefix (“icon” for icons), followed by one or more keywords (e.g., “icon joy happiness”), and then a dashed source segment (e.g., the source “nick milo” embedded in the filename). That structure makes icons discoverable and reusable later, because the system can reliably match files by keyword and preserve provenance. Without this discipline, reusing visuals becomes tedious: icons may exist, but they’re hard to locate and hard to trust.

From there, the method automates library creation. An Excalidraw Script Engine script scans an Obsidian vault via the Obsidian API, filters for non-markdown files whose base filename contains “icon” (case-insensitive), and sorts them alphabetically. The script then uses Excalidraw’s Automate API to reset the canvas and place each icon image into a grid layout—six columns by default, with rows added as needed. For each image, it calculates x/y coordinates based on the current column and row, adds the image to the canvas, and resizes it to fit within fixed width/height constraints while preserving aspect ratio. Once all images are placed, the script zooms to fit and switches the drawing into view mode so the icons can be copied into other documents without UI clutter.

A key usability step is making the library load automatically. The script is embedded into the Excalidraw file’s front matter using an “on load script” tag (so the icon grid regenerates whenever the drawing opens). Because Excalidraw expects the script content in a compact form, a helper “conversion” script reads the clipboard and strips newline characters (and collapses extra spaces) before embedding the final one-line script. This avoids manual cleanup and makes the setup repeatable.

The approach also includes debugging guidance: when running scripts from the Script Engine, errors can be harder to pinpoint, but the developer console allows defining the Automate API object (EA) and executing the script directly in the active view. The result is a repeatable pipeline: enforce icon filenames, auto-generate an icon library grid from vault files, and load it automatically into an Excalidraw workspace for fast reuse—turning visual assets into a navigable knowledge layer rather than scattered images in folders.

Overall, the core insight is that icon reuse becomes scalable only when visuals are named consistently and then rendered into a structured, auto-updating library that supports copy-paste workflows inside Excalidraw—making visual connections easier to maintain across a growing knowledge base.

Cornell Notes

The method turns an Obsidian vault of icon files into an auto-generated Excalidraw image library. It relies on a strict naming convention: filenames start with “icon,” include one or more keywords, and embed the image source after a dash. An Excalidraw Script Engine script scans the vault, filters non-markdown files whose names include “icon,” and lays them out in a grid on the canvas using Excalidraw Automate APIs. Each image is resized to fit fixed cell dimensions while preserving aspect ratio, then the canvas zooms to fit and switches to view mode for easy copy-paste. Finally, an “on load script” front-matter tag makes the library regenerate automatically when the Excalidraw file opens, with a helper that strips newlines for reliable embedding.

Why does the naming convention matter more than the icon artwork itself?

The automation depends on filenames as the index. The script filters vault files by checking whether the lowercase base filename contains “icon” and ignores markdown files. If icons aren’t named consistently (e.g., “Icon” vs “icon,” missing keywords, or inconsistent source formatting), the library won’t reliably include the right images or preserve provenance. The recommended pattern is “icon” + keywords (like “icon joy happiness”) + a dashed source segment (e.g., the source “nick milo” embedded in the filename), so the same file name can later support both reuse and source lookup.

How does the script decide which files become part of the icon library?

It uses the Obsidian API to retrieve all files in the vault, then filters them: (1) exclude markdown files by extension, and (2) include only files whose base name, converted to lowercase, contains the substring “icon.” This makes the selection case-insensitive and ensures only actual image files are used. The filtered list can be sorted alphabetically by comparing base names, which makes the grid predictable.

What turns a list of icon files into a usable Excalidraw grid?

Excalidraw Automate APIs place each image onto the canvas. After resetting the scene, the script tracks a current column and row. For each icon, it computes x/y coordinates using fixed cell width/height plus padding (e.g., x = column * (width + padding), y = row * (height + padding)). It adds the image element to the canvas, captures the created element id, then resizes it to fit within the cell while maintaining aspect ratio. When the column limit is reached (six columns), it advances to the next row.

Why is resizing necessary after adding images to the canvas?

Icons can have different native dimensions. The script calculates the element’s width/height ratio relative to the target cell dimensions. If the image would exceed the allowed height, it recalculates the scaling based on height; otherwise it fits based on width. It then reapplies the width and height so each icon fits neatly into the grid without overflowing.

How does the library become automatic when opening an Excalidraw file?

The icon grid script is embedded into the Excalidraw file front matter using an “on load script” tag (written as an Excalidraw on-load script value). When the Excalidraw document opens, the script runs in the background and regenerates the icon grid. Because embedding can be sensitive to formatting, a helper conversion step removes newline characters and collapses extra spaces so the script content fits cleanly into the front matter.

What’s the best way to debug when the Script Engine run fails?

Use the developer console. The console doesn’t automatically define the EA shorthand for Excalidraw Automate, so EA must be set manually (EA = excluder automate). The script also needs to run against an active view (click into the view first, then execute). This makes it easier to see where errors occur and to test functions interactively.

Review Questions

  1. What exact filename checks does the script perform to decide which vault files become icons, and why is case-insensitivity important?
  2. Describe how the script computes x/y placement for each icon and how it handles moving from one row to the next.
  3. What steps are required to make the icon library regenerate automatically on Excalidraw open, and why might newline removal be necessary?

Key Points

  1. 1

    Use a strict icon filename convention starting with “icon,” followed by keywords and a dashed source segment to make icons both searchable and reusable.

  2. 2

    An Excalidraw Script Engine script can scan an Obsidian vault, filter non-markdown files containing “icon” in the base name, and sort them for predictable output.

  3. 3

    Excalidraw Automate APIs can render a grid of icons by computing x/y coordinates from fixed cell dimensions and padding.

  4. 4

    After adding each image, resizing logic preserves aspect ratio so icons fit cleanly into the grid without distortion or overflow.

  5. 5

    Switching to view mode after rendering keeps the workspace copy-friendly while hiding editing tools.

  6. 6

    Embedding the script via an Excalidraw on-load front-matter tag makes the icon library regenerate automatically when the drawing opens.

  7. 7

    A clipboard-to-on-load-script conversion helper removes newlines and extra spaces to prevent formatting issues when embedding the script.

Highlights

Icon reuse scales only when filenames act like an index: “icon” + keywords + source in the filename enables reliable automation.
A single script can turn scattered icon files into a copy-pasteable Excalidraw grid by placing images using calculated x/y coordinates and aspect-ratio resizing.
Automatic regeneration comes from front-matter “on load script” embedding, with newline stripping to keep the embedded script valid.

Topics

  • Icon Naming
  • Excalidraw Automation
  • Obsidian Vault
  • Script Engine
  • Image Library