Skip to content

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

Scripts: FootageItem.replace() swaps in one file, as in After Effects

bflatastic883171eecebe
diff --git a/crates/script/src/prelude.js b/crates/script/src/prelude.js
index a33714314..b9108b2a1 100644
--- a/crates/script/src/prelude.js
+++ b/crates/script/src/prelude.js
@@ -1706,7 +1706,8 @@ Object.defineProperty(FootageItem.prototype, "mainSource", {
return this.__mainSource;
},
});
-FootageItem.prototype.replace = function (f) { __call("file.replaceFootage", { item: this.__id, path: __str(f) }); };
+// replace() swaps in one file, even a numbered still (replaceWithSequence brings a run), as in After Effects.
+FootageItem.prototype.replace = function (f) { __call("file.replaceFootage", { item: this.__id, path: __str(f), sequence: false }); };
FootageItem.prototype.replaceWithSequence = function (f, forceAlphabetical) {
__call("file.replaceFootage", { item: this.__id, path: __str(f), sequence: true, alphabetical: !!forceAlphabetical });
};
diff --git a/crates/script/src/tests.rs b/crates/script/src/tests.rs
index 875885c11..3f8190a73 100644
--- a/crates/script/src/tests.rs
+++ b/crates/script/src/tests.rs
@@ -1062,6 +1062,11 @@ fn footage_proxies_sequences_and_conform_rate() {
let paths: Vec<String> =
s.project.items.values().filter_map(|i| if let ItemKind::Footage(f) = &i.kind { Some(f.path.replace('\\', "/")) } else { None }).collect();
assert!(paths.iter().any(|f| f.contains("take_")), "replaced with the take sequence: {paths:?}");
+ // replace() swaps in the one file, even a numbered still, as in After Effects.
+ ok(&mut s, &format!("app.project.item(1).replace(new File('{}'))", p("shot_0002.png")));
+ let kinds: Vec<_> =
+ s.project.items.values().filter_map(|i| if let ItemKind::Footage(f) = &i.kind { Some((f.kind, f.path.replace('\\', "/"))) } else { None }).collect();
+ assert!(kinds.iter().any(|(k, f)| *k == effectcraft_engine::project::FootageKind::Still && f.ends_with("shot_0002.png")), "{kinds:?}");
let _ = std::fs::remove_dir_all(&dir);
}