Hi Sir_Ivan, I have been trying to send the output of an api call from js to jsx using async await but it just returns undefined. When I don't use async await it returns [object Promise] meaning that the api call had not been awaited properly. I have tried a lot of ways to make it work but as soon as I add the keyword 'await' the extendscript makes the output undefined. Can you please suggest some solution here?
Extendscripting scripting
This didn't work either . This is my function:
extendscript function:
output:
Oh, yes. You need to wrap csInterface.evalScript('$._PPP_.cmd()')
in promise,
here is a bit of explanation: https://stackoverflow.com/questions/74038268/what-does-await-new-promise-do
var csInterface = new CSInterface();
async function() {
const result = await new Promise(function (resolve) {
csInterface.evalScript('$._PPP_.cmd()', function(result) {
resolve(result)
})
})
}
As you said this is the code I used:
But it still outputs 'undefined'.
I even tried to delay the response using setTimeout because it takes time to generate the output of the api call but the premiere pro would alert 'undefined' right away. But that didn't work either.
The output prints fine in the terminal when I request it from the JS only. But I have been unable to send it to the JSX which is where I need it.
Still doesn't work. Can you tell in which part the problem might be?
- Edited
Try to go in your code step by step and see what could be the problem.
What apiCall returns?
apiCall() returns an object. Here's the apiCall function if it helps and the updated code I am using.
To be honest I'm bit confused what you are trying to achieve.
I would suggest to test each part separately and see what works and what doesn't.
Hey I have made some progress and the ouput being an object is not causing issue anymore.
But still the premiere pro is not able to receive the output of the api call.
In the attached screenshot you can see that there are 2 functions. The first function makes the api call and flattens the output to a string. And the second function sends data to premeire. But when it is called premiere shows not output. So, I put some alerts to check what was working and what wasn't. So when this function is called only the first alert works and then it doesn't respond or return any alert after that which probably means that the line "const result = await apiOutput0();" is never executed. That line works fine when checked in the js using console.log but while sending to jsx nothing gets executed after that line.
(Also the api call takes a few seconds to generate the output so I put the setTimeOut there but idk if that serves any objective or not)
I did follow your advice and the problem is in awaiting the output of the apiCall due to Extendscript being ECMA3. Have you had any experience with that. This is the code I am using right now, little simpler than what I was using before and this does not alert anything in Premiere Pro.
(I have already shared above the JSX function)