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

ScriptUI palette can't access document

Guide ,
Sep 26, 2014 Sep 26, 2014

Copy link to clipboard

Copied

Hi,

I've recently started Illustrator scripting for my own purposes, but it is sometimes difficult to transfer InDesign knowledge.

Could anybody please tell me what's wrong with the following trivial script?

#target illustrator

#targetengine "main"

function helloDocument() {

  try {

    alert(app.activeDocument.name);

  } catch( ex ) {

    alert(ex);

  }

}

var w = new Window("palette","Test",undefined,{ resizeable: true });

var b = w.add("button",undefined,"Here!");

b.onClick = helloDocument;

w.show();

In InDesign the targetengine "main" would be a no-go, because it is the only transient engine - variables are gone after run. Even though the "JavaScript Tools Guide CC" still describes the targetengine directive as supported by Illustrator CS5(!), I did not find a way to create an own targetengine. The "main" engine appears to work persistent in Illustrator - as mentioned in another thread. Even though I'd prefer an own playing ground, I can live with that failure for now.

Anyway, my actual problem is that the active document is not accessible from the button click handler. The palette window shows up and a click invokes the handler, but all I get is an exception "there is no document". When I change the "palette" to "dialog", the otherwise unmodified script works.

Thanks for any clues,

Dirk

TOPICS
Scripting

Views

864

Translate

Translate

Report

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
Adobe
Engaged ,
Sep 26, 2014 Sep 26, 2014

Copy link to clipboard

Copied

It seems to work by adding a pair or parentheses for a function:

b.onClick = helloDocument();

Votes

Translate

Translate

Report

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
Guide ,
Sep 26, 2014 Sep 26, 2014

Copy link to clipboard

Copied

Assigning the function itself is intended here.

Your suggestion would invoke it once and assign the result.

Votes

Translate

Translate

Report

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
Guide ,
Sep 26, 2014 Sep 26, 2014

Copy link to clipboard

Copied

In the meantime I found that if I launch my script via File/Scripts menu the #targetengine directive will do its duties.

I only had tried via startup script, assuming I would need some more unknown code to set up a menu entry, matching InDesign's scriptable menus.

Votes

Translate

Translate

Report

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 ,
Sep 26, 2014 Sep 26, 2014

Copy link to clipboard

Copied

LATEST

Hi Dirk, you need to use BridgeTalk to have your palette talk to Illustrator, see this recent post

Is it possible to use AI "selection sets" in script and scriptUI?

Votes

Translate

Translate

Report

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