Skip to content

Sample scripts

The ten scripts that come with Buhayin and what each does.

Buhayin comes with ten scripts. They are in the left list of the Scripts Manager, which you open from the Script view, and the storyboard window's Scripting toolbar can show a button for each. Each opens with its name and what it does as two comment lines. They use only buhayin.scene(), buhayin.selection() and buhayin.edit(), with print for the answer.

Some scripts act on the storyboard. They say so, and print a message when the scene has none. Sound Report and 3D Report are also in the Storyboard menu.

The scripts

ScriptWhat it does
Caption SearchLists the storyboard panels whose captions say a word, whatever the case. Change TERM, then run it.
Toggle LayerShows the current layer when it is hidden and hides it when it is shown.
Delete LayerDeletes the current layer, with what hangs from it. One undo brings it back.
Delete Hidden LayersDeletes every hidden layer in one step. What hangs from a hidden group stays unless it is hidden too.
Align Nodes HorizontallyLays the nodes of the layers selected in the Timeline in a row in the Node view, on the height of the first, left to right as they stand now, at least 100 apart.
Rename PanelsNumbers every storyboard panel again by the project's naming rules, in play order, hand numbers and locked names too. One undo puts the old names back.
Change Panel DurationGives the selected panels, or the current one, LENGTH frames each.
Set Proportional LengthsScales the selected panels to TOTAL frames together, each keeping its share of the time.
Sound ReportLists every sound clip of the project: its row, the sound, the frame it starts on and how many frames it plays.
3D ReportLists the 3D models the storyboard's panels hold. Set BY to "project" for every panel, "shot" for the shots of the selected panels or "panel" for the selected panels alone.

Scripts that take a value near the top, such as TERM, LENGTH, TOTAL and BY, are meant to be changed before you run them.

Reading one

This is Toggle Layer, the shortest.

// Toggle Layer
// Shows the current layer when it is hidden and hides it when it is shown.

const scene = await buhayin.scene()
const row = scene.rows.find((each) => each.name === buhayin.layer)
if (!row) {
  print("There is no current layer.")
  return
}
await buhayin.edit({ kind: "showLayer", layer: row.name, shown: !row.enabled })
print(`${row.name} is ${row.enabled ? "hidden" : "shown"}.`)

It finds the row for the current layer in scene.rows, and stops with a message if there is none. row.enabled is the layer's eye. The showLayer edit sets the eye to the opposite.

This is Sound Report. It only reads.

const scene = await buhayin.scene()
const tracks = scene.rows.filter((row) => row.kind === "sound")
if (tracks.length === 0) {
  print("The project has no sound.")
  return
}
for (const track of tracks) {
  print(`Sound track: ${track.name}`)
  for (const clip of track.clips) {
    print(`  ${clip.sound} · starts on frame ${clip.from} · ${clip.to - clip.from + 1} frames`)
  }
}

And this is Delete Hidden Layers. It shows how a list of edits is one undo step.

const scene = await buhayin.scene()
// The rows are listed top first with a group before what is in it, so the last goes first.
const hidden = scene.rows.filter((row) => row.kind !== "sound" && row.enabled === false).reverse()
if (hidden.length === 0) {
  print("No layer is hidden.")
  return
}
await buhayin.edit(hidden.map((row) => ({ kind: "deleteLayer", layer: row.name })))

Make your own from one

  1. Copy the code of one of the examples above into the Script view's code box.
  2. Type a new name in the Name box.
  3. Change it and choose Run.
  4. Choose Save when it does what you want.

The saved script joins the Saved list, and Scripts Manager… can put a button for it on the Scripting toolbar.