Copy link to clipboard
Copied
Hi
When I try to create a new document from an HTML extension by calling a jsx script the script freezes until Illustrator is put into focus (for example by clicking it)
Only after focus returns to Illustrator will the script continue, in the meantime the Illustrator icon will jump around like a nutter.
I have not tired this out on windows only mac.
To get around this I get main.js to exec 3 oascript comands
1) to create the document: oascript -e 'tell application "Adobe Illustrator" to make new document'
2) focus on Illustrator: oascript -e 'activate application "Adobe Illustrator"'
3) run the jsx: oascript 'do javascript "path/to/my/script.jsx"'
This works but there are some obvious drawbacks.
Has anyone managed to create via an extension a new document and have the script work on it without the need for focusing on Illustrator without the use of oascript?
If so how?
Interestingly enough, if one runs from the applescript editor
tell application "Adobe Illustrator" to make new document
it will work fine. but if one runs from terminal
oascript -e 'tell application "Adobe Illustrator" to make new document'
it freezes Illustrator and causes the Icon to jump like a nutter until refocus.
Regards
Trevor
What if you try first, the BridgeTalk.bringToFront() method trick?
Copy link to clipboard
Copied
What if you try first, the BridgeTalk.bringToFront() method trick?
Copy link to clipboard
Copied
Thanks, I'll give that a go tomorrow.
Where would I put it? straight after doc = app.documents.add(); ?
Copy link to clipboard
Copied
Why don't you use evalScript method in main.js?
Copy link to clipboard
Copied
Hi Ten
I had used the evalScript method and it causes the freeze described above.
If i first create the document with the oascript and then use evalScript then I run into problems of the evalScript being applied before the documents made.
Silly-v's suggestion sounds good, I'll try it out later today. I think I need to put BridgeTalk.bringToFront() before creating the doc. If I use this method then I would be able to use the evalScript which is what I'm after.
Thanks
Trevor
Copy link to clipboard
Copied
Hi Trevor,
CEP Javascript is non blocking. If you separate scripting document creation and call Extendscript methods. You need to waiting finished document creation.
Here is an POC
//CEP
var csi = new CSInterface();
csi.evalScript("makeDoc();", function(f){ //callback function can wait Extendscript callback.
if (f=="1") evalScript("alert(app.activeDocument.name)");
})
//Extendscript
function makeDoc(){
var doc = app.documents.add();
if (doc) return "1";
else return "0";
}
or You can use the PlugPlugExternalObjects events (to make custom event and dispatch it after document creation).
Copy link to clipboard
Copied
Thanks to both of you,
Ten I had tried the call back methods but they were problematic for me.
The BridgeTalk.bringToFront(); works pefectly
app.documents.add().pathItems.add().setEntirePath([[50,50],[400,500],[200,100]]);
Freeze - Bounce
BridgeTalk.bringToFront();
app.documents.add().pathItems.add().setEntirePath([[50,50],[400,500],[200,100]]);
No Freeze - No bounce
Thanks again
Trevor
Find more inspiration, events, and resources on the new Adobe Community
Explore Now