16 Replies Latest reply on Feb 1, 2010 11:36 AM by Laubender

    New document a single page - not spread

    Michael L Hale Level 5

      I'm sure it's simple but I still can't get my head around the InDesign DOM. How can I create a new document without the pages being in a spread?

       

      Here is what I have now

       

           function addDocument ( w, h ){
                var myDocument = app.documents.add();
                myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;
                myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;
                myDocument.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;
                myDocument.documentPreferences.pageWidth = w;
                myDocument.documentPreferences.pageHeight = h;
                // want only one page 'spread' and set the margins
                var myMasterSpread = myDocument.masterSpreads.item(0);
                var myMarginPreferences = myMasterSpread.pages.item(0).marginPreferences;
                myMarginPreferences.left = 0;
                myMarginPreferences.top = 0;
                myMarginPreferences.right = 0;
                myMarginPreferences.bottom = 0;
                myMarginPreferences.columnCount = 1;
                myMarginPreferences.columnGutter = 0;
                myDocument.pages[0].appliedMaster = myMasterSpread;
                return myDocument;
           }
        • 1. Re: New document a single page - not spread
          Peter Kahrel Adobe Community Professional & MVP

          Michael,

           

          > but I still can't get my head around the InDesign DOM

           

          That's how I feel about the PhotoShop DOM. You'd think that if you're familiar how one works you should be able to come to grips with another, but that's not my experience. PS is still a struggle.

           

          But anyway, the problem you describe is known. You'd think that setting facing pages to false would do the trick:

           

          myDocument.documentPreferences.facingPages = false;

           

          but it doesn't. I've seen an elaborate fix a while ago in a Swiss forum but I can't remember that. When I need a one-page master spread I simply delete a page. After your line

           

          var myMasterSpread = myDocument.masterSpreads.item(0);

           

          insert this one:


          myMasterSpread.pages.item(0).remove ();

           

          Must be page 0, not 1, because page 1 is applied to document page 1. You'd think that

           

          Then you end up with an inelegant one-page master spread with facing pages enabled, so you could still disable that.

           

          Peter

          • 2. Re: New document a single page - not spread
            Michael L Hale Level 5

            Thanks that did the trick. The next time you have trouble with Photoshop give me a shout in the Photoshop Scripting forum or at PS-Scripts and I will try help.

            • 4. Re: New document a single page - not spread
              Muppet Mark Level 5

              Peter, mikes code worked first time for me because the last newly created doc before the script created doc did not have facing pages. So I think the page removal should be in if statement.

               

              if (myMasterSpread.pages.length == 2) myMasterSpread.pages.item(0).remove ();

               

              else I some times get 'A document must have at least one page.'

              • 5. Re: New document a single page - not spread
                Laubender Adobe Community Professional & MVP

                @Peter:
                I think you mean the following thread:

                http://www.hilfdirselbst.ch/gforum/gforum.cgi?post=405554#405554

                 

                In essence Hans Haesler pointed out, that it might be a good idea to use the standard document preferences:

                 

                app.documents.add(true, app.documentPresets[0]);
                

                 

                 

                Uwe

                • 6. Re: New document a single page - not spread
                  Peter Kahrel Adobe Community Professional & MVP

                  Mark --

                   

                  > the page removal should be in if statement.

                   

                  Yes, true.

                   

                  P.

                  • 7. Re: New document a single page - not spread
                    Peter Kahrel Adobe Community Professional & MVP

                    Thanks, Uwe, that's the one

                     

                    Peter

                    • 8. Re: New document a single page - not spread
                      Steven.. Level 3

                      Facing pages can only be set before document is created. Changing the app preference is the way to go

                       

                           app.documentPreferences.facingPages = false;
                      
                           addDocument (100, 600);
                            
                           function addDocument ( w, h ){
                                var myDocument = app.documents.add();
                                myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;
                                myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;
                                myDocument.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;
                                myDocument.documentPreferences.pageWidth = w;
                                myDocument.documentPreferences.pageHeight = h;
                                // want only one page 'spread' and set the margins
                                var myMasterSpread = myDocument.masterSpreads.item(0);
                                var myMarginPreferences = myMasterSpread.pages.item(0).marginPreferences;
                                myMarginPreferences.left = 0;
                                myMarginPreferences.top = 0;
                                myMarginPreferences.right = 0;
                                myMarginPreferences.bottom = 0;
                                myMarginPreferences.columnCount = 1;
                                myMarginPreferences.columnGutter = 0;
                                myDocument.pages[0].appliedMaster = myMasterSpread;
                                return myDocument;
                           }
                      

                       

                      This is like changing the preference in dialog when creating new document

                      • 9. Re: New document a single page - not spread
                        Peter Kahrel Adobe Community Professional & MVP

                        Aha! Thanks, Steven.

                        • 10. Re: New document a single page - not spread
                          Steven.. Level 3

                          if developing for third party resetting preference is suggested

                           

                          var bFacingPages = app.documentPreferences.facingPages;
                          if (bFacingPages) app.documentPreferences.facingPages = false;
                          addDocument(100,600);
                          if (bFacingPages) app.documentPreferences.facingPages = true;
                          

                           

                          Otherwise the next time user opens New document dialog, they might not realize that you have changed preference of app.

                          • 11. Re: New document a single page - not spread
                            Laubender Adobe Community Professional & MVP

                            Stephan,

                             

                            sorry to say, but your suggestion is not working for me (InDesign CS4 6.0.4 German Version on Mac OS X 10.5.8).
                            Instead of generating a single page document above code uses part of the previous used document preference file.
                            What I am doing wrong?


                            See also the screen shots:
                            1_PreviousUsedSettings.png

                            1_PreviousUsedSettings.png

                            2_PreviousDocFromTheSettings.png

                            2_PreviousDocFromTheSettings.png

                            3_NewDocFromCode.png

                            3_NewDocFromCode.png

                             

                            //NewDoc_SinglePages_SingleMasterSpreadPage.jsx
                            //31.01.2010
                            
                            //DOES NOT WORK AS EXPECTED:
                            //1.No single page in MasterSpread[0]
                            //2.No single page file
                            //3.Therefore: marginPreferences, columnCount and columnGutter only for left pages as expected
                            
                            //AS EXPECTED:
                            //1.Number of pages generated as stated in previous used documentPreferences setting
                            
                            //Suggestion by Peter Kahrel:
                            //http://www.hilfdirselbst.ch/gforum/gforum.cgi?post=432223#432223
                            //Triggered by Stephan:
                            //http://forums.adobe.com/message/2556914#2556914
                            
                            // record current state
                            var state = app.documentPreferences.facingPages == true;
                            app.documentPreferences.facingPages = false;
                            //Function call for an A4 sized document:
                            myDoc = addDocSinglePageWidthHeight(210,297);
                            // restore state
                            app.documentPreferences.facingPages = state;
                            
                            //Function by: Michael L. Haile
                            //http://forums.adobe.com/message/2556113#2556113
                            //~ function addDocument ( w, h ){
                            //Edited by Uwe Laubender:
                            //function name
                            //MeasurementUnits=Millimeters
                            function addDocSinglePageWidthHeight ( w, h ){
                                      var myDocument = app.documents.add();
                                      myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
                                      myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;
                                      myDocument.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;
                                      myDocument.documentPreferences.pageWidth = w;
                                      myDocument.documentPreferences.pageHeight = h;
                                      // want only one page 'spread' and set the margins
                                      var myMasterSpread = myDocument.masterSpreads.item(0);
                                      var myMarginPreferences = myMasterSpread.pages.item(0).marginPreferences;
                                      myMarginPreferences.left = 0;
                                      myMarginPreferences.top = 0;
                                      myMarginPreferences.right = 0;
                                      myMarginPreferences.bottom = 0;
                                      myMarginPreferences.columnCount = 1;
                                      myMarginPreferences.columnGutter = 0;
                                      myDocument.pages[0].appliedMaster = myMasterSpread;
                                      return myDocument;
                                 };
                            

                             

                            The following code does what I want:

                            app.documents.add(true, app.documentPresets[0]);
                            
                            app.activeDocument.documentPreferences.pageWidth="100mm";
                            app.activeDocument.documentPreferences.pageHeight="200mm";
                            

                             

                            It generates a single sided document with a single page master spread, 100 x 200 mm.

                            Uwe

                            • 12. Re: New document a single page - not spread
                              Peter Kahrel Adobe Community Professional & MVP

                              Uwe,

                               

                              Try this:

                               

                              // record current state
                              var state = app.documentPreferences.facingPages == true;
                              app.documentPreferences.facingPages = false;
                              myDoc = app.documents.add ();
                              // restore state
                              app.documentPreferences.facingPages = state;

                               

                              // now continue with myDoc

                               

                              myDoc.marginPreferences etc

                              • 13. Re: New document a single page - not spread
                                Laubender Adobe Community Professional & MVP

                                Thank you, Peter.


                                But:

                                //Code2:
                                // record current state
                                var state = app.documentPreferences.facingPages == true;
                                app.documentPreferences.facingPages = false;
                                myDoc = app.documents.add ();
                                // restore state
                                app.documentPreferences.facingPages = state;
                                
                                // now continue with myDoc
                                myDoc.documentPreferences.pageWidth = "150mm";
                                myDoc.documentPreferences.pageHeight = "300mm";
                                

                                 

                                yields nothing new:

                                4_NewDocFromCode2.png

                                4_NewDocFromCode2.png

                                If I put in another line for facingPages set to false:

                                //Code 3:
                                // record current state
                                var state = app.documentPreferences.facingPages == true;
                                app.documentPreferences.facingPages = false;
                                myDoc = app.documents.add ();
                                // restore state
                                app.documentPreferences.facingPages = state;
                                
                                // now continue with myDoc
                                myDoc.documentPreferences.facingPages = false;
                                myDoc.documentPreferences.pageWidth = "150mm";
                                myDoc.documentPreferences.pageHeight = "300mm";
                                

                                I'll get the following doc:
                                5_NewDocFromCode3.png

                                5_NewDocFromCode3.png

                                which is not the thing I want, because masterSpreads.item(0) still consists of two pages…
                                So it seems that

                                app.documentPreferences.facingPages = false;
                                

                                in front of

                                myDoc = app.documents.add ();
                                

                                does nothing at all.

                                I use a German version of InDesign CS4 6.0.4 on a German Mac OS X 10.5.8. Maybe that's the point.

                                 

                                Uwe

                                • 14. Re: New document a single page - not spread
                                  Steven.. Level 3

                                  Something is interesting here. Your code created document with 1 page master on my computer. Even in your pictures you have 1 page spreads but with 2 page master ????

                                   

                                  To see if app.documentPreferences.facingPages = false; works, close all documents and check File->DocumentSetup Menu Dialog (Translated to German) the setting of facing pages should be toggled with that code.

                                   

                                  documents.add() is like pressing Ctrl+Alt+N where document with default setting are created.

                                   

                                  All we are doing in code is changing default setting and then creating default document.

                                   

                                  Try doing in the UI and checking if the result is the same.

                                   

                                  It would be weird for it to change based on version German etc.. since that only seems to affect strings displayed, However German does seem to be different as I have experienced problems that just showed up on German version.

                                  • 15. Re: New document a single page - not spread
                                    Laubender Adobe Community Professional & MVP

                                    Hi Steven,
                                    I checked the default document preferences in UI (no document is open). "Facing pages" is off. See screen shot:

                                    6_DefaultDocPreferences_NoOtherDocOpen.png

                                    6_DefaultDocPreferences_NoOtherDocOpen.png

                                    With "app.documentPreferences.facingPages = true;" I can change that to "Facing pages: on".
                                    "app.documentPreferences.facingPages = false;" will bring it back to "Facing pages: off".

                                     

                                    However, when I do "app.document.add()" or do it's equivalent in UI, InDesign takes the last used document preset to construct a new document.
                                    If the last used document preset happens to be one with option "Facing pages: on", the new doc will logically obtain all properties not included in the script. Therefore an "app.document.add()" only will yield in a document with all properties defined according to the last used document preset.

                                     

                                    To change this you can either:
                                    use a different document preset like the default preset "app.document.add(true, app.documentPresets[0])" which happens to be a single pages document by default with a master spread definition of one single page
                                    or try to give all the needed properties and remove master page number two :

                                    var myDoc = app.documents.add();
                                    
                                    with(myDoc.documentPreferences){
                                         facingPages = false;
                                         pageWidth = "150mm";
                                         pageHeight = "250mm";
                                         pagesPerDocument = 5;
                                         // ...
                                         };
                                    with(myDoc.viewPreferences){
                                         rulerOrigin = RulerOrigin.PAGE_ORIGIN;
                                         horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
                                         verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;
                                         // ...
                                         };
                                    with(myDoc.masterSpreads.item(0).pages.item(0).marginPreferences){
                                         top = "0mm";
                                         left = "0mm";
                                         right = "20mm";
                                         bottom = "0mm";
                                         columnCount = 1;
                                         // ...
                                         };
                                    //I know there might be a "myDoc.masterSpreads.item(1)", but it will never be applied to the doc pages
                                    //Therefore I can delete it. Cautiously I will put that in an if statement:
                                    if(myDoc.masterSpreads.item(0).pages.length>1){
                                            myDoc.masterSpreads.item(0).pages.item(1).remove();
                                            };
                                    

                                    With that approach in the beginning my master spread will always contain two pages. I cannot see the possibility to define my master spread to one page only in advance.
                                    Now I tried to implement your suggestion with "app.documentPreferences.facingPages = false;" in front of the code, but it does not influence the construction of the master spread.

                                     

                                    One word about "app.documentPresets[0]": I found that it's default after a fresh install of InDesign is "Facing pages: off". However you can edit this later to "Facing pages: on", so my bet is to stay with the solution working only with "app.document.add()", add all necessary properties and remove the needless master page when building single sided documents.


                                    Uwe

                                    • 16. Re: New document a single page - not spread
                                      Laubender Adobe Community Professional & MVP

                                      Follow up:

                                       

                                      Now I'm sure that the German version of InDesign behaves different to the American version. I just checked that with a friend in Egypt who is working with an American version of InDesign CS4 6.0.4.

                                       

                                      Uwe