Copy link to clipboard
Copied
Hi,
I am working on extension and one of the functions is: change source file to existing image item.
The flow of the function should be:
1. changing the source file in the file/folder level (Node fs package, .copy() method) = no problem here
2. after succcessfull copy, jsx function is called using evalScript (CSInterface lib) = no problem here
3. jsx function should .reload() the file source - according to AE Scripting documentation
app.project.item(index).mainSource.file.mainSource.reload()
But I realized in my project the only working structure (existing path to correct properties) is this one:
app.project.item(index).mainSource.reload()
(The code example attached below.)
I have auto-reloading turned on in AE Preferences.
The problem is that .reload() is not working in the moment of calling. This happens when using Extendscript and also when trying to reload via user interface (right-click on imported image item in Project > "Reload Footage"). By that time, I can see the image is already changed in the folder (the path to the image is the same), but in AE the preview still shows the old image source.
After repeating the "reload" several times or reopening app or just waiting and unfocusing the window to the other app and back to AE - it will finally change the source to new.
It seems like there is some time period (reaction time) between change of the source file and mirroring this into the AE (so it is replaceable for the new source).
I would like to know "when" I am able to reload source and the change will be made visible in AE.
But there is no callback or information on which I could hang on in my script.
How to ensure, that the image would be reloaded (change of image reflected) on some user (or script) action?
Because of this, it looks like .reload() is not functioning properly.
Please, how do you manage to resolve such situation?
Thank you very much:)
CODE EXAMPLE:
js part:
const assetPath = [path to asset];
await fileDialog({ accept: "image/jpg" })
.then(files => {
try {
fse.copy(files[0].path, assetPath)
.then(a => {
lib.evalScript("changeCustom('" + type + "', '" + name + "')", changeCustomResult);
})
.catch(err => catchError(err));
} catch (err) {
catchError(err);
}
}).catch(err => {
catchError(err);
});
jsx part:
function changeCustom(type, name) {
app.beginUndoGroup("Change image source");
var file = getAssetByName(name + ".jpg"); // returns item - app.project.item(i)
var result = "";
try {
file.mainSource.reload();
} catch(e) {
result = e;
}
app.endUndoGroup();
return result;
}
Copy link to clipboard
Copied
The thumbnail will update on a UI redraw call, which could be as trivial as setting a different time to jump to on your current comp's timeline, jumping to anotehr comp or some sort of that trickery. Point in case: The thumbnail is triggered by how the source footage is used somewhere, not the releoad procedure.
Mylenium