Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

fix(script): expose AVLayer transform property shortcuts (#816)

Nigel Ihza Firdausy74b842cc45f2
diff --git a/crates/script/src/prelude.js b/crates/script/src/prelude.js
index f50a968c5..7195835ff 100644
--- a/crates/script/src/prelude.js
+++ b/crates/script/src/prelude.js
@@ -1117,6 +1117,11 @@ AVLayer.prototype.constructor = AVLayer;
var P = AVLayer.prototype;
function def(name, get, set) { Object.defineProperty(P, name, { get: get, set: set }); }
def("source", function () { return __item(this.__info().source); });
+ // After Effects exposes the most common Transform properties directly on AVLayer.
+ // Return the original Property object, not its current value: scripts can keyframe it.
+ ["anchorPoint", "position", "scale", "rotation", "opacity"].forEach(function (name) {
+ def(name, function () { return this.transform[name]; });
+ });
def("width", function () { return this.__info().width; });
def("height", function () { return this.__info().height; });
def("threeDLayer", function () { return this.__info().threeDLayer; }, function (v) { this.__switch("threeD", v); });
diff --git a/crates/script/src/tests.rs b/crates/script/src/tests.rs
index b50a7bfb2..dacfe5de9 100644
--- a/crates/script/src/tests.rs
+++ b/crates/script/src/tests.rs
@@ -730,3 +730,23 @@ fn import_options_sequence_picks_one_still_or_the_run() {
assert_eq!(kind_of(&s, "shot_[0001-0003].png"), FootageKind::Sequence);
let _ = std::fs::remove_dir_all(&dir);
}
+
+#[test]
+fn script_av_layer_transform_shortcuts_return_live_properties() {
+ let mut s = session();
+ let o = ok(
+ &mut s,
+ r#"
+ var c = app.project.items.addComp("Shortcuts", 100, 100, 1, 5, 25);
+ var l = c.layers.addSolid([1, 0, 0], "S", 10, 10, 1);
+ l.position.setValue([30, 40]);
+ l.rotation.setValueAtTime(1, 45);
+ [l.position.value[0], l.transform.position.value[1], l.rotation.numKeys,
+ l.opacity === undefined, l.scale === undefined, l.anchorPoint === undefined]
+ "#,
+ );
+ assert_eq!(o.result, json!([30, 40, 1, false, false, false]));
+ s.undo();
+ let restored = ok(&mut s, "app.project.item(1).layer(1).rotation.numKeys");
+ assert_eq!(restored.result, json!(0));
+}