Hi!
I'm trying it in Illustrator. I'm trying to call the actionscript code from ExtendScript.
I read this two articles: http://forums.adobe.com/thread/634947?tstart=0 and http://cookbooks.adobe.com/post_Communicating_between_JavaScript_and_t he_CS_SDK_us-17383.html
They all propose the same technique, like var jsxInterface:HostObject = HostObject.getRoot( HostObject.extensions[ 0 ] )
I'm using the external script (not an embedded one) I added my script to manifest file:
<ScriptPath>./script.jsx</ScriptPath>
And then trying to call jsxInterface.init( this ) which is defined in my jsx file. But with no luck. I just got an exception.
It seems like jsxInterface.init is not defined after all (of course, I defined it in .jsx file)
Is there a way to call a CS SDK function from external ExtendScript script in Illustrator? Or a way to pass "this" object
to javascript for a later access?
Thank you!
Anastasiy,
Unfortunately, at least from what I've seen, we have only better
success with the embedded script so far. The only app that allows me
to use an external script is InDesign, in that, I used CSXS's
evalScript to call into a ExtendScript method. InDesign then loads
that script into a second extension where I can call all its methods.
But I just tried this technique in AI, and it didn't work.
thanks!
lee
Hi Anastasiy,
The HostObject technique described in the cookbook entry can be used with a script that is not embedded. The call to "jsxInterface.eval()" takes a string and you could get this string from anywhere (e.g. reading from an external file). The example in the cookbook shows the script embedded in order to save time reading the file (and to keep the code clean) at the expense of the SWF size.
Zak
Zak, I rewrote my code with the new technique, so I'm embedding JSX scripts inside application.
But now I faced (after 4 hours of trying to figure out, why my code isn't working at all)
a new issue that is preventing me from doing this on Photoshop CS5 on Mac OS 10.6.3 64 bit. / latest Photoshop 12.0.1 update
When embedded, the JSX script doesn't support "app" object completely! It's the very strange issue - while there IS an app object, I cannot acess it. Every time I'm trying to get its property (app.appName, app["appName"] or even for (var s in app) { ... } ) I get an exception, which tells me "General Photoshop error occured. This functionality may not be available in this version of Photoshop".
It works perfectly with the external script and gives an exception only when emebedded.
Is this a known issue?
Anastasiy,
Is the code that reliese on "app" being called from an event handler? Specifically and event handler that is fired from an OS event (not a Flex UI event)?
Something like a network data received event, a timer event, something that hails from the OS.
If so, that's a known issue for Mac OS (my preso at the Dev Summit touched on it briefly - http://my.adobe.acrobat.com/p33908050/).
There is a workaround of using Script Listener code to execute the needed functionality.
Regards
Bob
Bob, thank you for the answer
I got a large jsx script embedded into my app. It does a lot of work, including dealing with
documents, app object etc. It sets variables that are being used later on. Now, when I put
in this jsx a code that tries to access the "app" object, the script fails with an exception.
Here's the example cut down to show what's happening.
The code that evaluates the jsx code is called from CSXSWindowedApplication's applicationComplete event. The code is as follows:
[ Embed (source= "../assets/test.jsx" , mimeType= "application/octet-stream" )]
private static var _testJSX:Class;
.....
private function initApplication( e: Event ):void
{
var jsxManager: HostObject;
jsxManager =
HostObject.getRoot(HostObject['extensions'][0]);
jsxManager.eval( new _testJSX().toString() );
}
This one immediately fails on MAC 64 bit after "eval". Because it has the following code in the root:
alert('SUCCESS! foregroundColor object = '+app.foregroundColor);
The project files with ZXP that fails on Mac and works on Windows can be downloaded here: http://anastasiy.com/testApp.zip It's a actually a standard code with the above modifications.
Am I doing something wrong?
Hi Anastasiy,
Weird!
It looks like it does not work during a creationComplete event.
If you change your code to intitialize in a function, and call that function outside the creationComplete event, it works fine. Like so:
ExtendScript:
function initializeJSX(){
try
{
alert('SUCCESS! foregroundColor object = '+app.foregroundColor); } catch(e)
{
alert('ERROR: '+e.description);
}
}
MXML:
<?xml version="1.0" encoding="utf-8"?>
<csxs:CSXSWindowedApplication
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:csxs="com.adobe.csxs.core.*"
layout="absolute" historyManagementEnabled="false"
creationComplete="initApplication(event)">
<mx:Script>
<![CDATA[
[ Embed (source= "../assets/test.jsx" , mimeType= "application/octet-stream" )]
private static var _testJSX:Class;
[Bindable]
private var hostName:String = HostObject.mainExtension;
private var jsxManager: HostObject;
private function initApplication( e: Event ):void
{
jsxManager = HostObject.getRoot(HostObject['extensions'][0]);
jsxManager.eval( new _testJSX().toString() );
}
]]>
</mx:Script>
<mx:VBox height="100%" width="100%" verticalAlign="middle" horizontalAlign="center">
<mx:Button label="Run PS code" click="jsxManager.initializeJSX()" enabled="{hostName.indexOf('photoshop') > -1}"/>
</mx:VBox>
</csxs:CSXSWindowedApplication>
I presume you can get what you what by calling the function via a timer or some other event...
Harbs
Thank you Harbs! It's a very tricky solution
It will work, but I'll have to rewrite a lot of code again.
After that call I got a very big piece of code that is needed to be synchronized with other parts, and if I make it a timeout-call... a complexity of the code will rise enormousely ![]()
Anyway, as I can see it's a bug. I'll add it to the list
Well, Harbs, if I'm using PANEL_OPEN the initialization of the interface is seen when panel is opened
- buttons are changing, text changin etc. With creationComplete the panel opens just as smoothly as it can be.
The eval doesn't work either. The app object is completely unaccesible in the embedded script in the creationComplete event (on Mac only). As Bob said, there are other events that make it unaccesible as well.
The workaround you mentioned is cool, but I won't be able to understand my code after this and other workarounds. That will be so cool, if Adobe fixes this and other issues with the next updates.
Thank you!
North America
Europe, Middle East and Africa
Asia Pacific