8 Replies Latest reply on Aug 22, 2011 10:37 PM by Petteri_Paananen

    Adding section to active page

    Petteri_Paananen Level 4

      Hi

       

      I´m trying to create a very simple javascript for adding new section to active page. So far I have made following code:

       

      var myDoc = app.activeDocument;
      var numero = app.activeWindow.activePage.name;
      var numero2 = numero -1;
      myDoc.sections.add(myDoc.pages[numero2]);

       

      It basically works as it should, whren I double-click some page thumbnail in pages panel, that page will become active... and if I run the script at that point it usually adds section to active page pretty nicely....

       

      However, if I use that script with Configurator 2.0 and create a custom panel, with Add a section button (where I have attached that same javascript) InDesign starts to throw me some weird alert:

       

      alert.jpg

       

      If I answer yes, script will work as it should, but I would like to make it work so that users won´t get that alert at all....

      If I run that scrpt from Scripts panel, it works without alerts...

       

      Another thing I have tried to figure out is how to create some kind of error handler that would stop the script if active page already has a section start, now script generates a javascript error in those cases.... it would be more classy if simply nothing happened....

       

       

      Any help appreciated.... thanks

        • 1. Re: Adding section to active page
          John Hawkinson Level 5

          Does it work better with?:

           

          var numero = app.activeDocument.layoutWindows[0].activePage.name;

           

          just a guess.

          • 2. Re: Adding section to active page
            Petteri_Paananen Level 4

            No, it gives me same alert... thanks anyway....=)

            • 3. Re: Adding section to active page
              Harbs. Level 6

              I have not played with Configurator much.

               

              One thing you can try is using app.documents[0] instead of activeDcoument.

               

              You can also wrap the whole thing in a try/catch. This would probably solve both of your issues in one go...

               

              Harbs

              • 4. Re: Adding section to active page
                John Hawkinson Level 5

                In case it wasn't clear, if you

                try {
                 ...
                } catch (e) {
                  $.writeln("Error "+e.message+" at line "+e.line);
                }
                

                 

                then you'll know what it is complaining about, instead of being a mystery.

                • 5. Re: Adding section to active page
                  Petteri_Paananen Level 4

                  Thanks guys...=) but no luck here....

                   

                  And I noticed something quite weird. This script is meant to use with single pages, but when I accidentally used it with facing pages spreads, I got that same alert + script changed the way page numbers are marked below thumbs:

                   

                  pages.jpg

                   

                  It replaced 10-11 with 10,11

                   

                  I also tried

                   

                  try {
                  var myDoc = app.documents[0];
                  var numero = app.documents[0].layoutWindows[0].activePage.name;
                  var numero2 = numero -1;
                  myDoc.sections.add(myDoc.pages[numero2]);
                  } catch (e)
                  {  $.writeln("Error "+e.message+" at line "+e.line);}

                   

                  But I still have that same alert.... When I run that code in Extend Script ToolKit, I got following javascrip console message:

                   

                  Error undefined is not an object at line 2
                  Result: undefined

                  • 6. Re: Adding section to active page
                    Laubender Adobe Community Professional & MVP
                    It replaced 10-11 with 10,11

                     

                    Petteri,
                    nothing weird here: 10-11 means, that the whole spread belongs to a single section.
                    Now, after adding a new section at page 11, InDesign indicates with the comma between the page numbers that the spread belongs to two sections.
                    A second indicator is the tiny triangle at top of page 11.

                     

                    See also the following screen shot where one spread contains 4 pages and is part of three sections:

                     

                    Spread5pages3sections.png

                     

                    Uwe

                     

                    Message was edited by: Laubender

                    • 7. Re: Adding section to active page
                      John Hawkinson Level 5
                      try {

                      var myDoc = app.documents[0];

                       

                      Error undefined is not an object at line 2

                      Well, clearly you don't have an app.documents[0];. Perhaps app is wrong, or app.documents is wrong. So try printing out a bunch of these things to find out. Check app.reflect.properties and app.documents.length and all that stuff... Maybe even try BridgeTalk (shudder).

                      • 8. Re: Adding section to active page
                        Petteri_Paananen Level 4

                        @Laubender

                        Thanks for the clarification...=) InDesign is amazing peace of software, I have used it since version one (and even written 4 books about it) and still sometimes I learn something new. I have used sections many many times but I have never noticed that behaviour...

                         

                        @John

                        I have to study this little further. My problem is that I´m really a newbie with javascript. I have done quite a lot ActionScript but it´s just different enough to drive me crazy sometimes...=)

                         

                        Thanks anyway to everyone.....