Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Make new document with an Illustrator Extension

Guru ,
Nov 13, 2016 Nov 13, 2016

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

TOPICS
Scripting
2.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Nov 13, 2016 Nov 13, 2016

What if you try first, the BridgeTalk.bringToFront() method trick?

Translate
Adobe
Valorous Hero ,
Nov 13, 2016 Nov 13, 2016

What if you try first, the BridgeTalk.bringToFront() method trick?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Nov 13, 2016 Nov 13, 2016

Thanks, I'll give that a go tomorrow.

Where would I put it? straight after doc = app.documents.add(); ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 13, 2016 Nov 13, 2016

Why don't you use evalScript method in main.js?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Nov 13, 2016 Nov 13, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 14, 2016 Nov 14, 2016

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).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Nov 14, 2016 Nov 14, 2016
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines