Copy link to clipboard
Copied
Hi all.
I have code that imports a file into a project
var fileDepthSourceName = srtCarentFolder + "/Source_Crop.png"
app.project.activeItem.saveFrameToPng(0, File(fileDepthSourceName))
// $.sleep(5000)
f_ImportAsFootage(fileDepthSourceName, "Import");
The last line of code sometimes throws an error.
If before the last line I put the line
$.sleep(5000)
then everything happens normally.
It seems like a string
f_ImportAsFootage(fileDepthSourceName, "Import");
call occurs before the file is created.
Is it possible to replace the string-- $.sleep(5000) ---
into an infinite loop, the exit from which is possible after receiving the object of this file?
Copy link to clipboard
Copied
I don't think you can avoid having to put in some wait cycles. You can't control how fast the script interpreter processes the underlying AEGP commands and the same applies to the file handling, since it merely calls a system function and waits for it to execute and return specific states.
Mylenium
Copy link to clipboard
Copied
Yes, I want to write a loop to wait for this file.
What should it look like?
Copy link to clipboard
Copied
The typical way to do it would be to just add a manual refresh after the function. These only trigger once all previous functions have completed. No fancy loops required. Otherwise you could probably do something with checking the project item explicitly instead of just blindly loading the asset. A few ways I could imagine.
Mylenium
Copy link to clipboard
Copied
This is the function
// @include "E:/Progs/adobe/Scripts/AE/f_findAVItemByName.jsx";
// @include "E:/Progs/adobe/Scripts/AE/f_findFolderByName.jsx";
function f_ImportAsFootage(element, importFolderName) {
var k = 1;
while(File(element).exists == false) {
k + 1
}
var ImpFileOpt = new ImportOptions()
ImpFileOpt.file = new File(element)
ImpFileOpt.importAs = ImportAsType.FOOTAGE
app.project.importFile(ImpFileOpt)
var stringElement = String(element)
var arraystringElement = stringElement.split("/")
var fullName = arraystringElement[arraystringElement.length - 1]
var carentName = f_findAVItemByName(fullName)
var imoprtFolder = f_findFolderByName(importFolderName)
carentName.parentFolder = imoprtFolder;
carentName.selected = false
}
There is an error on line
ImpFileOpt.file = new File(element)
------------------------------------------------------------------------------------------------------------------