2 Replies Latest reply on Feb 1, 2012 3:07 PM by Trevorׅ

    "Main" and "Session" Targetengine Paradox.

    Trevorׅ Adobe Community Professional

      1) I need to use a "session" targetengine because I a using a "window" type UI window which like the "palette" type cannot be run using the "main" target engine.

       

      2) I want however that on the press of a button on the UI a script should be run in the "main" targetengine as it uses a lot of memory which I want dumped on conclusion of the script's execution.

       

      3) I would like to avoid using 2 separate files one with the UI which activates the other file with the main function using the doScript command but my feeling is that this might be the only option.  I would however like to know how to do this as I don't know .

       

      The script below illustrate one of my pathetic (failed) attempts at solving the problem.

       

      Would much appreciate help on the problem

       

       

       

       

      #target "InDesign"
      #targetengine "session"
      
      target = "#target 'InDesign'";
      targetengine="#targetengine 'main'";
      
      w = new Window ("window", undefined, undefined,{ resizeable: true, borderless: false} );
      myPanel = w.add ("panel");
      w.add ("statictext", undefined, "main");
      mb1=w.add ("button", undefined, "Press here!");
      w.show();
      mb1.onClick = function () {
          app.doScript(target,ScriptLanguage.javascript, undefined, UndoModes.entireScript);
          app.doScript(targetengine,ScriptLanguage.javascript, undefined, UndoModes.entireScript);
          app.doScript(test, ScriptLanguage.javascript, undefined, UndoModes.entireScript);}
      myVarm = "session target engine";
      
      
      function test(){
      alert("If you don't see this alert then the function is not being executed");
      ww = new Window ("window", undefined, undefined,{ resizeable: true, borderless: false} );
      myStatic = ww.add ("statictext", [0, 0, 700, 100], "If this stays on the screen then the target engine has not been changed to \"main!\"\r\rIf You can get this message not to stay on the screen then you are a better scripter than me\r\rThis is not a very difficult achivement !!",{multiline: true });
      myStatic.justify = "center";
      ww.show();
      myMainVar = "Should so error if value is tried to be got from the data browser after the script has run";
      }
      
        • 1. Re: "Main" and "Session" Targetengine Paradox.
          Marc Autret Level 4

          I'm afraid you need to embed the whole code as a string in a single app.doScript (including the #targetengine directive).

          Since the test function is declared in the session engine, it is unknown from the main engine, so you probably have to pass the body through func.toSource() and to call the func:

           

           

          #targetengine "mySession"
          
          w = new Window("window", undefined, undefined, {resizeable:true, borderless:false} );
          myPanel = w.add ("panel");
          w.add("statictext", undefined, "main");
          mb1=w.add("button", undefined, "Press here!");
          
          mb1.onClick = function()
              {
              app.doScript("#targetengine 'main'\r"+test.toSource()+"();",
              ScriptLanguage.javascript, undefined, UndoModes.entireScript);
              }
          
          w.show();
          
          function test(){alert($.engineName);}
          

           

          @+

          Marc

          • 2. Re: "Main" and "Session" Targetengine Paradox.
            Trevorׅ Adobe Community Professional

            Thanks a lot Marc, works great.

             

            I think it would have taken me a few years to figure out the toSource bit!

             

            My next stage is to figure out how to transfer variables to the "main" session, which I see is discussed in the scripting guide using “script arguments”.