Skip to main content
Known Participant
May 1, 2015
Answered

Getting the name of the appliedAlternateLayout

  • May 1, 2015
  • 2 replies
  • 647 views

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

This topic has been closed for replies.
Correct answer Laubender

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.alternateLayout !== ""){

        myStartsOfAlternateLayouts[mySections.alternateLayout] = mySections.pageStart.documentOffset;

        };

   

    };

for(x in myStartsOfAlternateLayouts){

    //Results will show the names of the different alternate layouts:

    $.writeln(x);

    //Results will show the index numbers of the pages where the alternate layouts start:

    $.writeln(myStartsOfAlternateLayouts);

   

    };

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.

Uwe

2 replies

Community Expert
May 5, 2015

Hi James,

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

mySections.pageStart

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.

Uwe

Known Participant
May 5, 2015

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.

LaubenderCommunity ExpertCorrect answer
Community Expert
May 2, 2015

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.alternateLayout !== ""){

        myStartsOfAlternateLayouts[mySections.alternateLayout] = mySections.pageStart.documentOffset;

        };

   

    };

for(x in myStartsOfAlternateLayouts){

    //Results will show the names of the different alternate layouts:

    $.writeln(x);

    //Results will show the index numbers of the pages where the alternate layouts start:

    $.writeln(myStartsOfAlternateLayouts);

   

    };

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.

Uwe