10 Replies Latest reply on Jul 8, 2009 6:09 PM by John.Kordas

    Session engine and Export as Binary

    John.Kordas Level 1

      I seem to have a problem exporting as binary when the script uses the targetengine session. I tried working through the Export As Xhtml examples but have not had any luck. If anyone could point me in the correct direction that would be appreciated, or if it is not possible save me time in trying to get this to work.

       

       

      Here's an example of a simple dialog that works as a jsx but not a jsxbin.

       

      
      

      #target indesign
      #targetengine "session"
      if(app.documents.length != 0){
      var myDialog = new Window('palette','Starting Pg No');
          myDialog.dPgNo = myDialog.add('panel',undefined,'File details');
          myDialog.dPgNo.alignChildren = 'left';
          myDialog.dPgNo.myPgNo = myDialog.dPgNo.add('group');
          myDialog.dPgNo.myPgNo.myGroup = myDialog.dPgNo.myPgNo.add('group');
          myDialog.dPgNo.btnGroup = myDialog.dPgNo.add('group');
          with (myDialog.dPgNo){
              myPgNo.myGroup.orientation = 'column';
              myPgNo.myGroup.alignChildren = 'right';
              myPgNo.myGroup.preferredSize = [90,15];
              myPgNo.myGroup.st  = myPgNo.myGroup.add('statictext',undefined,'Your Doc starting page is:');
              myPgNo.et = myPgNo.add('edittext', undefined, app.activeDocument.pages[0].name)
              btnGroup.btn = btnGroup.add('button', undefined, 'Update');
              btnGroup.alignment = 'right';
          }
      myDialog.show();

       

      myDialog.dPgNo.btnGroup.btn.onClick = function() {
          var myPagestart = myDialog.dPgNo.myPgNo.et.text;
          myDialog.close();
          if (app.activeDocument.pages[0].name != myPagestart){
              app.activeDocument.pages[0].appliedSection.continueNumbering = false;
              app.activeDocument.pages[0].appliedSection.pageNumberStart = parseInt(myPagestart);
              app.activeDocument.pages[0].appliedSection.sectionPrefix = "";
              alert("Your document start page has been changed to "+myPagestart+".");
          }
      myDialog.show();
      }
      }else{
          alert("Please open a document and try again.");
          }

        • 1. Re: Session engine and Export as Binary
          Steven.. Level 3

          The way to call it is with dummy jsx file like this

           

          #target indesign
          #targetengine "session"
          
          var myFile = new File (app.activeScript.parent.parent.fsName + '/myFileName.jsxbin');
          
               if (myFile.exists)
                    app.doScript(myFile) ,ScriptLanguage.JAVASCRIPT
               else 
                    alert(myFile.fsName + " doesn't exist");
          

           

          Good luck

           

          Steven

          http://scriptui.com

          • 2. Re: Session engine and Export as Binary
            John.Kordas Level 1

            Thanks Steven,

             

            I've been tied up with acouple of other scripts so did not get a chance to got through this until now and I'm still getting the same result as if I export the above script as a binary file.

             

             

            I call the script above SessionTest.jsxbin applied this to the example you posted and placed the SessionTestCall.jsx with the SessionTest.jsxbin file in the same folder and tried to run the SessionTestCall.jsx file. The window pops up in Indesign but closes straight away, as as if you execute the SessionTest.jsxbin file.

             

            Have I got this correct?

            
            

            #target indesign
            #targetengine "session"

            var myFile = new File (app.activeScript.parent.fsName + '/SessionTest.jsxbin');

                 if (myFile.exists)
                      app.doScript(myFile ) ,ScriptLanguage.JAVASCRIPT
                 else
                      alert(myFile.fsName + " doesn't exist");

            • 3. Re: Session engine and Export as Binary
              Steven.. Level 3
               app.doScript(myFile ) ,ScriptLanguage.JAVASCRIPT

              should be

               app.doScript(myFile ,ScriptLanguage.JAVASCRIPT)

              I don't know if that will help

              • 4. Re: Session engine and Export as Binary
                John.Kordas Level 1

                Unfortunately Steven the change still causes the window to pop open then close straight away.

                 

                Cheers, John.

                • 5. Re: Session engine and Export as Binary
                  liedzeit Level 2

                  Maybe you have to reset userinteractionlevel? I have had this recently. Window popping up and disappearing again.

                   

                  Ralf

                  • 6. Re: Session engine and Export as Binary
                    Thomas B. Nielsen Level 3

                    Hi John,

                     

                    Do not export the dummy file as binary.

                    targetengine session can not be loaded from a jsxbin file, so instead you use a dummy file in jsx, and let that load the jsxbin (the code you do not want others to see, or edit).

                    • 7. Re: Session engine and Export as Binary
                      John.Kordas Level 1

                      Thanks liedzeit and Thomas,

                       

                      I've checked myuserInteractionLevel

                       

                      $.write(app.scriptPreferences.userInteractionLevel) = 1699311169 ( INTERACT_WITH_ALL )

                       

                      interestingly while looking for some info on the userInteractionLevel I stumbled on a reply post form Robert_Tkaczyk (adobescripts.com) and I saw a script PhotoManager_CS3 I thought I'd give a try.  After running acouple of tests I ran the above script again and this time I got:

                       

                      $.write(app.scriptPreferences.userInteractionLevel) = 1699640946 ( NEVER_INTERACT )

                       

                      Not that I want to move away form my issue but would this cause issues if other scripts change settings that you expect to be something else?

                       

                      In any case I'm still getting the window popping up and closing straight away.  I also tried what Thomas suggested and removed:

                       

                      #target indesign
                      #targetengine "session"

                       

                      from the top of the SessionTest.jsxbin file but still get the same result.  Any other suggestions are welcome.

                      • 8. Re: Session engine and Export as Binary
                        John.Kordas Level 1

                        This has probably been done by someone else but I know I've had to check theuserInteractionLevel before and to save me time I put this together so i can quickly check what the current setting is.

                         

                        
                        
                        

                        var myUsrInter = app.scriptPreferences.userInteractionLevel;
                        switch (myUsrInter)
                        {
                        case 1699640946:
                          alert("Your userInteractionLevel is set to NEVER_INTERACT");
                          break;
                        case 1699311169:
                          alert("Your userInteractionLevel is set to INTERACT_WITH_ALL");
                          break;
                        case 1699311170:
                          alert("Your userInteractionLevel is set to INTERACT_WITH_ALERTS");
                          break;
                        }

                        • 9. Re: Session engine and Export as Binary
                          Thomas B. Nielsen Level 3

                          Hi John,

                           

                          Create a folder in your Indesign Scripts Folder Panel, lets call it myFolder.

                          In that folder we will put two files, the first is your script, as a binary, the second is a loader file as jsx.

                           

                          The folowing should be pasted into ESTK and exported as jsxbin, save the file in myFolder as myScript.jsxbin:

                           

                          app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
                          if(app.documents.length != 0){
                          var myDialog = new Window('palette','Starting Pg No');
                              myDialog.dPgNo = myDialog.add('panel',undefined,'File details');
                              myDialog.dPgNo.alignChildren = 'left';
                              myDialog.dPgNo.myPgNo = myDialog.dPgNo.add('group');
                              myDialog.dPgNo.myPgNo.myGroup = myDialog.dPgNo.myPgNo.add('group');
                              myDialog.dPgNo.btnGroup = myDialog.dPgNo.add('group');
                              with (myDialog.dPgNo){
                                  myPgNo.myGroup.orientation = 'column';
                                  myPgNo.myGroup.alignChildren = 'right';
                                  myPgNo.myGroup.preferredSize = [90,15];
                                  myPgNo.myGroup.st  = myPgNo.myGroup.add('statictext',undefined,'Your Doc starting page is:');
                                  myPgNo.et = myPgNo.add('edittext', undefined, app.activeDocument.pages[0].name)
                                  btnGroup.btn = btnGroup.add('button', undefined, 'Update');
                                  btnGroup.alignment = 'right';
                              }
                          myDialog.show();

                           

                           

                           

                          myDialog.dPgNo.btnGroup.btn.onClick = function() {
                              var myPagestart = myDialog.dPgNo.myPgNo.et.text;
                              myDialog.close();
                              if (app.activeDocument.pages[0].name != myPagestart){
                                  app.activeDocument.pages[0].appliedSection.continueNumbering = false;
                                  app.activeDocument.pages[0].appliedSection.pageNumberStart = parseInt(myPagestart);
                                  app.activeDocument.pages[0].appliedSection.sectionPrefix = "";
                                  alert("Your document start page has been changed to "+myPagestart+".");
                              }
                          myDialog.show();
                          }
                          }else{
                              alert("Please open a document and try again.");
                          }

                           

                          The folowing should be pasted into ESTK and saved as jsx, save the file in myFolder as myLoader.jsx:

                           

                          #target indesign
                          #targetengine "session"
                          var myScript = loadScript("myScript.jsxbin");
                          if(myScript != undefined) {
                              // execute it
                              eval(myScript);
                          }

                           

                          function getScriptsFolderPath() {
                              try {
                                  var script = app.activeScript;
                              } catch(e) {
                                  // we are running from the ESTK
                                  var script = File(e.fileName);
                              }
                              return script.path + "/";
                          }

                           

                          function loadScript (filename) {
                              var file = File(getScriptsFolderPath() + filename);

                           

                              var script = undefined;
                              if (file.exists) {
                                  file.open();
                                  script = file.read();
                                  file.close();
                              } else {
                                  alert("Failed to locate the file: " + filename);
                                  exit();
                              }
                              // we return the script rather than calling eval() right here
                              // because the results of eval() are only valid within the
                              // scope of the function that calls eval()
                              return script;
                          }

                           

                          Now just open Indesign and run the script myLoader.jsx and it should work.

                          • 10. Re: Session engine and Export as Binary
                            John.Kordas Level 1

                            Thanks Thomas

                             

                            works no probs.

                             

                            Much appreciated, John.