Skip navigation
Currently Being Moderated

Cannot call CS SDK function from javascript

Jun 21, 2010 10:25 PM

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!

 
Replies
  • Currently Being Moderated
    Jun 22, 2010 5:57 PM   in reply to Anastasiy Safari

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 23, 2010 2:43 PM   in reply to Anastasiy Safari

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 24, 2010 9:08 AM   in reply to Anastasiy Safari

    Can you explain what you're doing? There is nothing special about embedding the script; it's merely a way to get the script read into memory so it can be passed to jsxInterface.eval() as a string. Did you try reading in the script?

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 28, 2010 9:38 AM   in reply to Anastasiy Safari

    The technique described in cookbook will work for InDesign, Illustrator, Photoshop, and Bridge. For the others, consider using CSXSInterface.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 19, 2010 10:03 AM   in reply to Anastasiy Safari

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 20, 2010 1:41 PM   in reply to Anastasiy Safari

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 22, 2010 1:53 PM   in reply to Anastasiy Safari

    What happens if you finish the initializing on a PANEL_OPEN event?

     

    The other question is if it's a problem on creationComplete per se, or it's a problem accessing app right after the script is evaled. Maybe try eval() in an init event, and seeing if that helps?

     

    Good luck!

    Harbs

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 23, 2010 11:59 AM   in reply to Harbs.

    .

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points