Placing image hangs the script unless it's in Async/Await wrapper
Without async/await I have nothing on a screen but a spinning wheel. When I try to close it, suddenly a picture appears, then I press "cancel" and have the result on the page. But if I use async/await on the main() function (and placing of the image can be many function calls below), it works just fine.
Hangs:
main();
function main() {
const myDocument = app.activeDocument;
const imagePath = "C:\\Users\\<User>\\Desktop\\Capture11.JPG";
const imageFrame = myDocument.rectangles.add({
geometricBounds: ["36px", "36px", "260px", "180px"],
strokeWeight: 0,
strokeColor: myDocument.swatches.item('None')
});
imageFrame.place(imagePath);
}Works:
await main();
async function main() {
return new Promise(async(resolve, reject) => {
const myDocument = app.activeDocument;
const imagePath = "C:\\Users\\Ooo\\Desktop\\Capture11.JPG";
const imageFrame = myDocument.rectangles.add({
geometricBounds: ["36px", "36px", "260px", "180px"],
strokeWeight: 0,
strokeColor: myDocument.swatches.item('None')
});
imageFrame.place(imagePath);
resolve();
});
}
I'm new to Adobe scripting and that was really confusing to me. Is there some documentation that might help clarify things like that? Thank you in advance!
