• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
2

Calling functions from UI palette

Participant ,
Nov 12, 2012 Nov 12, 2012

Copy link to clipboard

Copied

Hello,

From what I understand, you can't call complex functions from a scripted UI palette, only from "dialog" windows (which are usless in my case) because I need the persistance of a palette.

I have a series of scripts in use now that are  accessed from the usual "file-scripts folder" within Illustrator itself (about 27 of them).  I want to script a palette window so users can acces them without the usual mouse clicks down the menu system.

I'm able to call a simple "Hello World" type function using the "onClick()" method from a button of a scripted palette window, but I cannot use my regular working scripts inside a function that's called from the button.  In X-Code, I was able to write my scripts individually, then just add them to a main floating window via a separate function when they were completed.  But, I'm finding Javascript a little more tricky.

If I copy my other's script code into the function in the palette window script, it runs, but it runs before I click the button! --  After in runs, then the palette window is displayed(?).  If I try to use the execute() method with "onClick", the script just opens in the SDK, it will not and does run in Illustrator.

I take both of these as clear indications that I have no clue what I'm doing (or that I'm trying to do the impossible).

I did find someone with a similar problem, but they were scripting After Effects and were offered this solution:

system.callSystem ('afterfx -r "/C/Program Files/Adobe/Adobe After Effects CS3/Support Files/Scripts/GlobalVars.jsx"');

Is there anything I can do in Illustrator that will allow me to call (or execute) my other scripts/functions and have them execute within Illustrator?

Thanks for any and all help!

TOPICS
Scripting

Views

20.7K

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

correct answers 1 Correct answer

Participant , Nov 14, 2012 Nov 14, 2012

Well, here it is!!

I found this link:

http://www.davidebarranca.com/2012/11/scriptui-bridgetalk-persistent-window-examples/

(If you stumble on this by chance, thank you davide barranca!)

Now, I can make changes to the scripts in just one location and everyone will get the updates once they restart their window. 

Works like a charm and is just what I was needing!  Thank you all again for your help!

#target illustrator

var scriptToLoad = new File("S:/NEW SCRIPTS/JAVASCRIPTS IN USE NOW/02) Make/01b) Shap

...

Votes

Translate

Translate
Adobe
Community Expert ,
Nov 12, 2012 Nov 12, 2012

Copy link to clipboard

Copied

the feature has always been broken, and for the longest I thought it was impossible to overcome, we finally found out a way to make it work, look here for an interesting reading about the topic and a script by Moluapple

http://forums.adobe.com/message/4402921#4402921

and here another script by me

http://forums.adobe.com/message/4820011#4820011

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
Participant ,
Nov 12, 2012 Nov 12, 2012

Copy link to clipboard

Copied

Thanks!  I'll check it out.  I'm not sure I'll understand that much depth into coding the UI, but I'll definitely give it a shot!

One question before I dive into it so I don't have to ask later.  Does/do those method(s) allow you to load external scripts, say from a server, so you could make one change to the script and have it propogate down to all users?

Thanks.

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 ,
Nov 12, 2012 Nov 12, 2012

Copy link to clipboard

Copied

kemango, your existing functions and scripts will certainly not work, you'll have tweak them a little bit to make them BridgeTalk ready.

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
Guru ,
Nov 12, 2012 Nov 12, 2012

Copy link to clipboard

Copied

Brokenā€¦ Im not sure on thatā€¦ Dialog is modal so it blocks out focus until cancel or okā€¦ The problem with palette is getting current document/app status and the only way is through bridgetalk messagingā€¦ In your case the called script should be able to do thisā€¦ Also look at the bridgetalk class cross DOM functions like run scriptā€¦ These should read and bridgetalk for you but I have heard of issues with theseā€¦

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
Participant ,
Nov 12, 2012 Nov 12, 2012

Copy link to clipboard

Copied

Will do...  Thanks for the help and the pointers in the right direction.  I can feel the skullcramps already.

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 ,
Nov 12, 2012 Nov 12, 2012

Copy link to clipboard

Copied

The problem with palette is getting current document/app status

that sounds like broken ,  in the sence that it can not communicate with the application directly, it has to BridgeTalk to itself.

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
Guru ,
Nov 12, 2012 Nov 12, 2012

Copy link to clipboard

Copied

In PS it won't even persistā€¦ Now that be not playing ball at allā€¦

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 ,
Nov 12, 2012 Nov 12, 2012

Copy link to clipboard

Copied

not at all Mark, Adobe doesn't play ball, from the guide:

Floating palette: Also called modeless dialog, allows activity in other application windows. (Adobe

PhotoshopĀ® does not support script creation of palette windows.)

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
Participant ,
Nov 12, 2012 Nov 12, 2012

Copy link to clipboard

Copied

Thanks for the info, gentlemen....

I'm sure I'll be back for more help.  Not sure if it's worth all the trouble when they are perfectly content with using the current method of running the scripts.  It's just I have to know how this crazy s**t works.  When I finally do figure it out, I'm sure it will be time for the next version to come out and things will change.  It's a shame that such a powerful tool (I write scripts for workflow automation in a production art department) doesn't get more attention where needed.  But, I guess that's why they pay us, right?

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
Mentor ,
Nov 12, 2012 Nov 12, 2012

Copy link to clipboard

Copied

klemango wrote:

I have a series of scripts in use now that are  accessed from the usual "file-scripts folder" within Illustrator itself (about 27 of them).  I want to script a palette window so users can acces them without the usual mouse clicks down the menu system.

Not sure if I am on the right track in interpreting your request, but would Script Bay offer any viable solutions for your needs? I am however not sure if it works from a network drive/server (not sure why it wouldn't as its just pointers to folders it seems). Anyway if I am way off base then I apologize, otherwise maybe it will be helpful in some way as a more direct way for handling scripts if thats indeed what your after?

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
Participant ,
Nov 13, 2012 Nov 13, 2012

Copy link to clipboard

Copied

Yes, it does help.  And, several of the artists at work use it all day.  They group several of the scripts into specific folders and just double click the folder.  The scripts inside that folder will then run in order.  It's a huge time saver!

That's exactly what got me interested in learing about scripting the UI.  When there was just a few scripts, it wasn't such a big problem.  But, as their numbers grew, I began looking for a long-term solution to funneling down through folders of scripts in the Illustrator File menu.  We use a two monitor set-up at work and it would be great to having a floating palette just sitting on one of them waiting for commands.

Because UI scripting is new to me, can anyone offer any real good resources to learn about scripting Bridgetalk and/or the UI?  I did download Mark's suggestion to read the UI document by Peter Kahrel and that was my first look at the UI code.  Great explanations and progressive code-flow from the beginning.  It really helped get me hooked into learning more.

As usual, the Tools Guide, like all other Adobe reference materials, is really only useful once you know somewhat how to code.  If you're a beginner, it might as well be written in Mandarin Chinese!  And, as others have said, the examples given are few.  Tthey never seem to have an example for what I'm trying to accomplish.  If I EVER master all the printing paramaters, I will throw a party and EVERYONE is invited.

Now it's time for more meat and potatoes behind the scenes stuff.

If anyone could offer any resources that would help, I'll check them all out.

And, as always, thank you for your time and your willingness to help.  From what I've already learned in these forums about Applescript and now JS, I wonder what that knowledge would've cost me in a classroom? 

Klemango

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
Participant ,
Nov 13, 2012 Nov 13, 2012

Copy link to clipboard

Copied

Ah, I should've taken the time to actually READ the info in the tools guide first, eh?

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
Mentor ,
Nov 13, 2012 Nov 13, 2012

Copy link to clipboard

Copied

Ok, I see. Well I wont try and talk above my current comprehension (still learning myself) and your already in good hands with Muppet Mark and CarlosCanto.

klemango wrote:

I'm able to call a simple "Hello World" type function using the "onClick()" method from a button of a scripted palette window, but I cannot use my regular working scripts inside a function that's called from the button.  In X-Code, I was able to write my scripts individually, then just add them to a main floating window via a separate function when they were completed.  But, I'm finding Javascript a little more tricky. If I copy my other's script code into the function in the palette window script, it runs, but it runs before I click the button! --  After in runs, then the palette window is displayed(?).  If I try to use the execute() method with "onClick", the script just opens in the SDK, it will not and does run in Illustrator.

That sounds weird that it would execute before the onClick is called? I will say that I have scripted window palettes using onClick() which then reference an #include to another JS file to execute and it works fine, I have also nested other #include's inside these files being called as well. So I guess you could build a palette window which executes scripts on user interaction (click a button) and even daisy chains scripts together using #include's? But then thats why I suggested ScriptBay as it already eloquently does this. How one gets to building something like ScriptBay is beyond me however, it's really impressive by Harbs.

klemango wrote:

Yes, it does help.  And, several of the artists at work use it all day.  They group several of the scripts into specific folders and just double click the folder.  The scripts inside that folder will then run in order.  It's a huge time saver! That's exactly what got me interested in learing about scripting the UI.  When there was just a few scripts, it wasn't such a big problem.  But, as their numbers grew, I began looking for a long-term solution to funneling down through folders of scripts in the Illustrator File menu.  We use a two monitor set-up at work and it would be great to having a floating palette just sitting on one of them waiting for commands.

Hmmm... that sounds perfect for Scriptbay and what it was intended for.

----

I gotta be honest though I might not be accurately understanding the full scope of what your trying to accomplish (plus obviously your trying to just learn as well), and if your wanting to get into BridgeTalk then thats beyond myself at this point. So again I refer you back to Muppet Mark, CarlosCanto and others for sound advice. šŸ˜‰

Sorry if I added any confusion and noise to your thread, I just found it to be an interesting topic. I am probably approaching it from a too basic level however, sorry if I misunderstood.

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
Participant ,
Nov 13, 2012 Nov 13, 2012

Copy link to clipboard

Copied

No, not at all!  After reading part of the tools guide, I'm wondering if I can just include the #include statement inside the function I'm calling, then execute the script from outside the window?  Something like this?:

var bt = new BridgeTalk;

bt.target = "illustrator";

fileobj.execute()

***where fileobj is the external script.  However, when using execute() from within the palette, the scripts native program, which in this case is the ESToolkit, is the one that opens the program.  I need to learn how to tell Illustrator itself to run the script as it would from the File-Scripts menu.  That is, if it's even possible to do that.

What I'm trying to do in a nutshell is run separate, already written scripts (they are run from the "File-Scripts" menu in illustrator now) from a palette window by just selecting a button within the palette.  I was able to do this with Applescripts by just including the code within the X-Code script itself.  Pretty simple when I look back on it now......

But, from what I understand, because the Adobe Suite has individual programs, with individual scripting capibilites, I've somehow got to not only tell the palette button what I want it to do, but give the receiving application what it needs to do it's job.  In this case, I believe that means I need to send illustrator the script it needs to run, or somehow reference a location to a script that it can load, then run.  Once it get it what it needs, Illustrator will (or should) then run in its native environment and fulfill the task the script tells it to perform.

My problem lies in the middle between the palette and Illustrator.  And, if I'm digesting what Carlos and Mark are telling me correctly, this means I need to use the Bridgetalk API to perform this function.  That's what I'm trying to get a grasp on now.  If I'm correct in my thinking, the palette runs in its own persistance engine and uses the API to  send requests and replies between different/separate applications.  He's the middleman who needs to be given the properly formatted request to give to any particular app.  I get the theory, I just don't know the proper procedure and/or information I need to include inside the palette code to get it to do what I need.  I'll keep reading!

Thanks for all your posts!  Keep 'em coming! 

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
Participant ,
Nov 13, 2012 Nov 13, 2012

Copy link to clipboard

Copied

Also, just a note:  I don't need to worry about any return values to deal with.  Each script in Illustrator performs a specific function unto itself.  They stand alone, so to speak.  So, I just need a way to invoke them.

Thanks.

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 ,
Nov 13, 2012 Nov 13, 2012

Copy link to clipboard

Copied

To force Illustrator as the operative app, put #target illustrator at the start of the script.

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
Participant ,
Nov 13, 2012 Nov 13, 2012

Copy link to clipboard

Copied

Hi Larry, thanks for the info.  In this case, does #target illustrator need to be at the beginning of the entire script?  Or, within and at the beginning of the function code?

Also, I can't seem to get this to work:

illustrator.executeScript(scriptfile);

And, I can't seem to find a working example, either.

You guys should get together and write a book.  One that has real world problems and examples in it.  Downloadable PDF.  I'd buy it.

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 ,
Nov 13, 2012 Nov 13, 2012

Copy link to clipboard

Copied

kemango, I like what you're doing, we've told you since the beginning regular calls don't work, and still you're trying to find out how to make it work. I did the exact same thing, I thought "hmm...maybe there's something so simple that everyone before me just missed", but no, I couldn't find anything...but at the end, it's all good, you'll learn a lot by trying a bunch of different things, and who knows, you might find a way.

in the mean time, look at my code in the selectLayers script, that's as basic as it gets, it does not return values, it just sends a request to select items in a layer.

...ok that code is not the most basic, let me make you a similar sample with a basic call..

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 ,
Nov 13, 2012 Nov 13, 2012

Copy link to clipboard

Copied

here a simple script to select the top object

#target Illustrator

#targetengine main

var win = new Window('palette', 'Select Top Object');

var btnSelect = win.add('button', undefined, 'Select');

btnSelect.onClick = function(){

    var bt = new BridgeTalk;

    bt.target = "illustrator";

        var script = "\n" +

        "app.activeDocument.pageItems[0].selected = true;\n" +

        "app.refresh();\n"

    bt.body = script;

    bt.send();

}

win.center();

win.show();

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
Participant ,
Nov 13, 2012 Nov 13, 2012

Copy link to clipboard

Copied

Thanks Carlos.  I think I'm this way because I've never had any formal training and my results have always come by the way of trial/error.  But, you're right, I have to exhaust myself trying 1,000 ways to do something before it clicks.  It's kinda like putting together a 5,000 piece puzzle that's a single solid color.  Torture to say the least, but worth it in the end.  When I read your statement calling them "regular" calls, that got me thinking about this:

(I've read yours and Moluapple's code and I think I need to correct myself on something....)

I was under the impression the palette itself was a completely separate entity.  Living on it's own within it's own engine, generated by the Toolkit. Acting as a sort of a traffic cop between apps. Do I now understand that when you #target an app that the window is generated within it's own engine, within and inclusive to that app?

If it is within the app, is my thinking that the palette is not a third party, but part of the app correct?  And, as such, does it now have a direct relationship with the app?  If so, are the function calls now considered a somewhat "local" ,but not in the same space, call in relation to the app?  Even though it's still an API?   I'm probably overthinking this, but it helps me to understand the "big" picture.

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
Participant ,
Nov 13, 2012 Nov 13, 2012

Copy link to clipboard

Copied

Sorry, was typing that while you replied.  I see now the #target and engine are IN the function.  That was one of my earlier questions and where my though processes were going.  I thought that since functions were local code, that I might have to have the #include inside the function.  But, I didn't know since I've never used #target before.  I'm going to give this a try.

Now, is there a way to load a script from an external library and run it (to keep the main code to a minimum)?

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 ,
Nov 13, 2012 Nov 13, 2012

Copy link to clipboard

Copied

#target Illustrator - if you run from the ESTK or double click on the file, #target tells the appropriate app to run the file, ignored if you run the script directly from Illustrator

#targetengine - don't have a proper technical definition but without it a 'palette' window won't persist.

as you see in the example, the script needs to be serialized as a text string and sent to illustrator. Illustrator receives the text string, puts it back into code (probably using eval() internally) and executed.

Now, is there a way to load a script from an external library and run it (to keep the main code to a minimum)?

I would say yes, as long as it gets properly serialized before it gets sent to illustrator.

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 ,
Nov 13, 2012 Nov 13, 2012

Copy link to clipboard

Copied

....as you can see in my selectLayers script I have a separate function that gets sent to illustrator, I think that function could live in a separate file and get loaded with #include

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
Participant ,
Nov 13, 2012 Nov 13, 2012

Copy link to clipboard

Copied

That didn't make any sense, did it?  I was typing the above while thinking of to many things at once.  Please disregard the one just above.

By looking at your code, I see that the statements are stored in the variable script, which is assigned to the body, then sent.  But, I'm also seeing each statement encased in quotes and with + in between.  These then, are what's being sent to illustrator to execute?

Is that what is needed for each line of the original script?

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