13 Replies Latest reply on Apr 6, 2012 10:21 PM by John Hawkinson

    how to add new page with new marginal preferences?

    govind_85 Level 1

      Hello,

      can anybody tell me? how to add new page with specific marginal preferences?is it possible to add margin setting at time adding page?

        • 1. Re: how to add new page with new marginal preferences?
          csm_phil Level 4

          Hi Govind,

           

          Please try the below 2 JS code.

           

          1. This below JS code is will create a new document and adding margin preferences.

           

          myDocument = app.documents.add(); 
          with (myDocument.pages.item(0).marginPreferences){ 
          columnCount = 3; 
          //columnGutter can be a number or a measurement string. 
          columnGutter = "1p"; 
          bottom = "6p" 
          //When document.documentPreferences.facingPages == true, 
          //"left" means inside; "right" means outside. 
          left = "6p" 
          right = "4p" 
          top = "4p" 
          }
          

           

           

           

          2. The below JS code is working in active Document.

           

          var myDoc = app.activeDocument;
          var myPg = myDoc.pages[-1];
          var myLastPage = myDoc.pages.add(LocationOptions.AT_END, myPg);
          with(myLastPage.marginPreferences){
               bottom = "6p" 
               left = "6p" 
               right = "4p" 
               top = "4p" 
               }
          

           

           

           

          thx

          csm_phil

          1 person found this helpful
          • 3. Re: how to add new page with new marginal preferences?
            govind_85 Level 1

            Hello sir,

            when we add page using doc.pages.add(LocationOptions.AFTER,currPage,withProperties).is it possible give marginPreferences in add method?how to use 3rd parameter in add() method to change marginPreferences

            setting?

            • 4. Re: how to add new page with new marginal preferences?
              csm_phil Level 4

              Hi Govind,

               

              What you expect have u tested the 2nd script code. you can add the values whatever you want. Else please tell briefly?

               

              thx

              csm_phil

              • 5. Re: how to add new page with new marginal preferences?
                Harbs. Level 6

                FWIW, "with" is generally frowned on as bad practice (for a number of reasons). This is a much better way to set many properties at once:

                 

                myDocument = app.documents.add(); 
                myDocument.pages.item(0).marginPreferences.properties = { 
                          columnCount : 3,
                          //columnGutter can be a number or a measurement string. 
                          columnGutter : "1p",
                          bottom : "6p",
                          //When document.documentPreferences.facingPages == true, 
                          //"left" means inside; "right" means outside. 
                          left : "6p",
                          right : "4p", 
                          top : "4p" 
                }
                

                and:

                 

                var myDoc = app.activeDocument;
                var myPg = myDoc.pages.item(-1);
                var myLastPage = myDoc.pages.add(LocationOptions.AT_END, myPg);
                myLastPage.marginPreferences.properties = {
                          bottom : "6p",
                          left : "6p",
                          right : "4p", 
                          top : "4p"
                }
                
                • 6. Re: how to add new page with new marginal preferences?
                  csm_phil Level 4

                  Hi Harbs,

                   

                  We know your genius, i agree with your feedback becasue, i learnt from you lot of things,

                   

                  May i know if you said "with" is bad practice then why should adobe realsed the InDesign Scripting guide using more places in "with" concepts. So in this case still Adobe don't know "with" is the bad concepts so adobe need to change the InDesign CS5 scripting guide, "properties" instead of "with".

                   

                  please clarify to me and also explain the problems i want to learn.

                   

                   

                  thx

                  csm_phil

                  • 7. Re: how to add new page with new marginal preferences?
                    [Jongware] Most Valuable Participant

                    Part of Harbs' genius comes from using Google when needed. (I think )

                     

                    http://blog.boyet.com/blog/javascriptlessons/javascript-for-c-programmers-the-with-stateme nt-considered-harmful/ .. and many more can be found with "with statement considered harmful".

                     

                    There is nothing wrong with setting the properties in one line, except that it gets progressively harder to read, understand, maintain, and update:

                     

                    myDoc = app.activeDocument;
                    var myLastPage = myDoc.pages.add(LocationOptions.AT_END, undefined, {marginPreferences:{bottom:"6p", left:"6p", right:"4p", top:"4p"} });
                    

                     

                    Note that since you are using 'LocationOptions.AT_END', you don't have to use a reference to any page. That is only required when you want to insert a page anywhere except at the end or the start.

                    • 8. Re: how to add new page with new marginal preferences?
                      [Jongware] Most Valuable Participant

                      csm_phil wrote:

                       

                      .. May i know if you said "with" is bad practice then why should adobe realsed the InDesign Scripting guide using more places in "with" concepts. So in this case still Adobe don't know "with" is the bad concepts so adobe need to change the InDesign CS5 scripting guide, "properties" instead of "with".

                       

                      If you read the articles on why "with" is considered harmful, you can see that Adobe's usage in the example scripts is perfectly alright.

                       

                      I use "with" myself all the time, as it is a convenient shortcut when used properly. There is an added penalty in the form of a slightly longer running time, but use it I mainly to construct dialogs -- hardly a "time critical" function, and using "with" they are considerably easier to read, maintain, etc.

                      • 9. Re: how to add new page with new marginal preferences?
                        John Hawkinson Level 5
                        If you read the articles on why "with" is considered harmful, you can see that Adobe's usage in the example scripts is perfectly alright.

                        Err....I would not agree.

                         

                        But clearly your milage may vary.

                        • 11. Re: how to add new page with new marginal preferences?
                          Harbs. Level 6

                          Yes. Google is everyone's friend...

                           

                          Part of the reason I say not to use with particularly in InDesign comes from experience.

                           

                          "with" performs poorly performance-wise and jumps through all kinds of hoops to work at all. I once had a really obscure issue with InDesign dialogs, "with" and local variables. I don't remember all the details but the solution was to get rid of "with"...

                           

                          The reason Ole used "with" for the script samples was to retain consistancy between the different languages in the examples -- not because it was inherently good...

                           

                          When setting multiple properties, "properties" has the advantage that you only need to interact with the C++ level once, so it's inherently more efficient than any other method. The fact that it's easy to read is just an added plus...

                           

                          Harbs

                          • 12. Re: how to add new page with new marginal preferences?
                            csm_phil Level 4

                            Hi Harbs,

                             

                            The bleow you said you faced some probelms while using the "with" now you said you recommended don't use "with" its okay. When you faced the problems why you not to intimate to Adobe if you tell the problems to Adobe they will alert to modify and realsed the Scripting Guide for your method like "propeties" so in this case you have not identify to adobe now you said i faced the problems. Anyway now you please highlight to adobe and next version Adobe InDesign CS6 they have to use your way. So easily to beginner to learn this is my suggestion.

                             

                            When setting multiple properties, "properties" has the advantage that you only need to interact with the C++ level once, so it's inherently more efficient than any other method. The fact that it's easy to read is just an added plus...

                             

                            thx

                            csm_phil

                            • 13. Re: how to add new page with new marginal preferences?
                              John Hawkinson Level 5

                              It's probably far too late to get any changes into InDesign CS6, pull out your calendar and look when it's expected to ship...

                               

                              But also, it's hard to get Adobe to put resources in to scripting. Blowing those resources rewriting the sample scripts is not really where it's at.