mirror of
https://github.com/storytold/effectcraft.git
synced 2026-10-14 19:27:05 -04:00
- engine: History keeps undone lines as branches; edit.history.list/goto; History panel tree; MCP history tool - puppet.recordPin / puppet.recordOptions; viewer Cmd-drag records; Record Options form - effects::plugin (EffectPlugin trait, register_plugin, API v1); effectcraft-plugin (wasmi, sandboxed, fuel-limited); effect.plugins.load/list - ScriptUI: engine scriptui model + layout + scriptui.* commands; script crate scriptui.js and script-host threads (dialogs block show()) - File ▸ Scripts: install script / ScriptUI panel, sample scripts, window.scriptPanel - host test: bit-identical renders across runs and thread counts Co-Authored-By: Claude Opus 5.5 <[email protected]>
38 lines
1.4 KiB
React
38 lines
1.4 KiB
React
// Sort Layers by In Point — an EffectCraft sample script (original work, MIT OR Apache-2.0).
|
|
//
|
|
// Reorders the selected layers of the active composition (all layers when none are selected)
|
|
// so the layer that starts first is on top. Layers with the same in point keep their order.
|
|
// One undo step.
|
|
|
|
(function sortLayersByInPoint() {
|
|
var comp = app.project.activeItem;
|
|
if (!(comp instanceof CompItem)) {
|
|
alert("Sort Layers by In Point: open a composition first.");
|
|
return;
|
|
}
|
|
var layers = comp.selectedLayers;
|
|
if (layers.length === 0) {
|
|
layers = [];
|
|
for (var i = 1; i <= comp.numLayers; i++) layers.push(comp.layer(i));
|
|
}
|
|
if (layers.length < 2) return;
|
|
|
|
// The slots the layers occupy now (stack indices, top first).
|
|
var slots = layers.map(function (l) { return l.index; }).sort(function (a, b) { return a - b; });
|
|
var order = layers
|
|
.map(function (l, k) { return { layer: l, inPoint: l.inPoint, k: k }; })
|
|
.sort(function (a, b) { return a.inPoint - b.inPoint || a.k - b.k; });
|
|
|
|
app.beginUndoGroup("Sort Layers by In Point");
|
|
// Place each layer, earliest first, in the next slot from the top.
|
|
for (var j = 0; j < order.length; j++) {
|
|
var target = slots[j];
|
|
var layer = order[j].layer;
|
|
if (layer.index === target) continue;
|
|
var anchor = comp.layer(target);
|
|
layer.moveBefore(anchor);
|
|
}
|
|
app.endUndoGroup();
|
|
writeLn("Sorted " + layers.length + " layer(s) by in point.");
|
|
})();
|