3 Replies Latest reply on May 5, 2015 11:38 AM by JamesHaney

    Getting the name of the appliedAlternateLayout

    JamesHaney Level 1

      I am trying to solve an issue with exporting JPEG versions of InDesign pages.


      The exportFile command gets an error if there are alternate layouts since if you just tell it to output page 1, it doesn't know whether you mean page 1 of the first layout, or one of the other layouts.


      In the Export dialog box, you can specify "alternateLayoutName:pageNumber" i.e. "Horizontal Layout:1" .


      In order to supply this information I am trying to extract the name of the alternate layout from the current page, however that doesn't seem to be an accessible value in the DOM.


      curPage.appliedAlternateLayout returns a [section]

      and there does not appear to be an object curPage.appliedAlternateLayout.name


      Does anyone know of a way around this?


      James Haney

        • 1. Re: Getting the name of the appliedAlternateLayout
          Laubender Adobe Community Professional & MVP

          James, to output page 1 of a document, you can use the index of a page of a document.
          You need not to use its name property and a string value for this.


          myPageToExport = app.documents[0].pages[0];


          will do the job.


          But how do you know where an alternate layout is starting and ending?

          You could check the Section collection of a document and look for the value of alternateLayoutLength.
          The name of an alternate layout is the value of the property alternateLayout of a specific Section


          Here a code snippet, that could do the job for the index of every starting page of an alternate layout:


          var myDoc = app.documents[0];
          var mySections = myDoc.sections.everyItem().getElements();
          var myStartsOfAlternateLayouts = [];
          for(var n=0;n<mySections.length;n++){
              //It seems, that sometimes a new section could force the value of alternateLayout of a Section to an empty string
              //Could be a bug in CS6.
              //So we will ignore empty strings:
              if(mySections[n].alternateLayout !== ""){
                  myStartsOfAlternateLayouts[mySections[n].alternateLayout] = mySections[n].pageStart.documentOffset;
          for(x in myStartsOfAlternateLayouts){
              //Results will show the names of the different alternate layouts:
              //Results will show the index numbers of the pages where the alternate layouts start:


          Note: Read the comments in the code.
          I found, that sometimes alternateLayout could yield an empty string.

          Could be a bug in CS6 where I tested this code.



          • 2. Re: Getting the name of the appliedAlternateLayout
            Laubender Adobe Community Professional & MVP

            Hi James,

            could you find something useful in my code snippet for your task?




            could also be used to store the starting page (as a Page object) of an alternate layout directly.

            The documentOffset value of such a page is storing the index value of that page.


            As it seems you cannot start with a Page object itself to read out in every case or instance of a page, if a page is considered part of this or that alternate layout. At least there are some difficulties to do so.

            Instead you could loop through all sections of a document to extract and gather useful information like I did with my snippet using an associative array.


            On the other hand, the value of the property appliedAlternateLayout of a Page object will return a Section object.

            But if a section will not start at the beginning of an alternate layout, the string returned from the property alternateLayout of that particular section will return an empty string as it seems.

            Have to test this again with CS6 and versions above.



            • 3. Re: Getting the name of the appliedAlternateLayout
              JamesHaney Level 1

              I ended up figuring it out basically exactly as you described.


              Once I took a hard look at the DOM I figured out that I needed to get the Section first in order to access the AlternateLayout.


              It is working perfectly now.