• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Adjust Layout Script Not working properly.

Explorer ,
Apr 25, 2022 Apr 25, 2022

Copy link to clipboard

Copied

I'm using "AdjustPageItems" or "//AdjustLayout_modified.jsx" script to move all items on every page. I have the document with 700+ pages. I divided the document into sections. When I select last page from script menu, it only moves items from page 1 until page 30.  I think script is ignoring any section mark, or section breaks.  Does anyone have any suggestions other than removing all sections?

AhmetSamsa_0-1650934018910.png

 

TOPICS
Bug , Scripting

Views

821

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 26, 2022 Apr 26, 2022

@Laubender is spot on. I made a file with two sections—"A" and "B"—with pages numbers starting at 1 in each. The myPageNames array was 1,2,3,4,1,2,3,4 which won't work. I changed the script to use page specifiers instead of page names and seems to work correctly now, but specifiers are a bit ugly to look at. See what you think. A refinement would be to make a list for the UI of combined Section prefix and page number.

- Mark

 

Edit: changed to mm, minor adjustments to script.

 

/*  AdjustLayout_
...

Votes

Translate

Translate
Community Expert ,
Apr 25, 2022 Apr 25, 2022

Copy link to clipboard

Copied

It's likely a limitation of the script—probably the way it addresses pages. Can you post the script so we can see what's going on?

- Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 25, 2022 Apr 25, 2022

Copy link to clipboard

Copied

This is the script. "https://github.com/ShinShinman/ID-scripts/blob/master/AdjustLayout_modified.jsx
Or script located in "\Scripts Panel\Samples\JavaScript\AdjustPageItems" (one of default sample script from Adobe)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

Hi Ahmet,

yes, it's an issue how pages are addressed.

There is a name property with page objects in scripting.

With alternate layouts sections are introduced to the document. Sections that could contain pages with the same name in other sections. A page name is not unique in InDesign. And that's by definition.

Obviously the script cannot work with a situation where page names are not unique in a given document.

 

Well, and here we have it if I am looking at this function myGetPageNames() in AdjustPageItems.jsx that is delivered with every version of InDesign:

 

function myGetPageNames(){
	var myPageNames = new Array;
	for(myCounter = 0; myCounter < app.activeDocument.pages.length; myCounter ++){
		myPageNames.push(app.activeDocument.pages.item(myCounter).name);
	}
	return myPageNames;
}

 

That array, and also the code that is working with the array of page names, should be abandoned.

 

An array of selected pages from the GUI of the script should either contain the page objects themselves or at least the documentOffset numbers which will reflect the position of the pages in the document

 

That could mean a major rewrite, I think…

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

@Laubender is spot on. I made a file with two sections—"A" and "B"—with pages numbers starting at 1 in each. The myPageNames array was 1,2,3,4,1,2,3,4 which won't work. I changed the script to use page specifiers instead of page names and seems to work correctly now, but specifiers are a bit ugly to look at. See what you think. A refinement would be to make a list for the UI of combined Section prefix and page number.

- Mark

 

Edit: changed to mm, minor adjustments to script.

 

/*  AdjustLayout_modified2.jsx

    Moves the content of even/odd pages by specified amounts; attempts to get
    objects back into the correct position after a master page margin change
    and/or page insertion.

    Quick modification to use page specifiers rather than page names
*/

function main() {
    //Make certain that user interaction (display of dialogs, etc.) is turned on.
    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
    if (app.documents.length != 0) {
        if (app.activeDocument.pageItems.length != 0) {
            myDisplayDialog();
        }
        else {
            alert("Document contains no page items.");
        }
    }
    else {
        alert("Please open a document and try again.");
    }
}
function myDisplayDialog() {
    var myLabelWidth = 70;
    var mm = 2.83465;
    var myDialog = app.dialogs.add({ name: "Adjust Layout" });
    var myPageSpecifiers = myGetPageSpecifiers();
    with (myDialog.dialogColumns.add()) {
        with (borderPanels.add()) {
            with (dialogColumns.add()) {
                with (dialogRows.add()) {
                    with (dialogColumns.add()) {
                        staticTexts.add({ staticLabel: "Start Page:", minWidth: myLabelWidth });
                    }
                    with (dialogColumns.add()) {
                        var myStartPageDropdown = dropdowns.add({ stringList: myPageSpecifiers, selectedIndex: 0 });
                    }
                }
                with (dialogRows.add()) {
                    with (dialogColumns.add()) {
                        staticTexts.add({ staticLabel: "End Page:", minWidth: myLabelWidth });
                    }
                    with (dialogColumns.add()) {
                        var myEndPageDropdown = dropdowns.add({ stringList: myPageSpecifiers, selectedIndex: myPageSpecifiers.length - 1 });
                    }
                }
            }
        }
        with (borderPanels.add()) {
            with (dialogRows.add()) {
                with (dialogColumns.add()) {
                    staticTexts.add({ staticLabel: "Even Pages", minWidth: myLabelWidth });
                    staticTexts.add({ staticLabel: "Horizontal:", minWidth: myLabelWidth });
                    staticTexts.add({ staticLabel: "Vertical:", minWidth: myLabelWidth });
                }
                with (dialogColumns.add()) {
                    staticTexts.add({ staticLabel: "" });
                    var myEvenXField = measurementEditboxes.add({ editValue: -10 * mm, editUnits: MeasurementUnits.millimeters });
                    var myEvenYField = measurementEditboxes.add({ editValue: 0, editUnits: MeasurementUnits.millimeters });
                }
            }
        }
        with (borderPanels.add()) {
            with (dialogRows.add()) {
                with (dialogColumns.add()) {
                    staticTexts.add({ staticLabel: "Odd Pages", minWidth: myLabelWidth });
                    staticTexts.add({ staticLabel: "Horizontal:", minWidth: myLabelWidth });
                    staticTexts.add({ staticLabel: "Vertical:", minWidth: myLabelWidth });
                }
                with (dialogColumns.add()) {
                    staticTexts.add({ staticLabel: "" });
                    var myOddXField = measurementEditboxes.add({ editValue: 10 * mm, editUnits: MeasurementUnits.millimeters });
                    var myOddYField = measurementEditboxes.add({ editValue: 0, editUnits: MeasurementUnits.millimeters });
                }
            }
        }
    }
    var myResult = myDialog.show();
    if (myResult == true) {
        var myStartPageSpecifier = myPageSpecifiers[myStartPageDropdown.selectedIndex];
        var myEndPageSpecifier = myPageSpecifiers[myEndPageDropdown.selectedIndex];
        if (myCheckPageRange(myStartPageSpecifier, myEndPageSpecifier) == true) {
            var myEvenX = myEvenXField.editValue;
            var myEvenY = myEvenYField.editValue;
            var myOddX = myOddXField.editValue;
            var myOddY = myOddYField.editValue;
            myDialog.destroy();
            myAdjustPages(myEvenX, myEvenY, myOddX, myOddY, myStartPageSpecifier, myEndPageSpecifier);
        }
        else {
            myDialog.destroy();
            alert("Invalid page range.");
        }
    }
    else {
        myDialog.destroy();
    }
}
function myAdjustPages(myEvenX, myEvenY, myOddX, myOddY, myStartPageSpecifier, myEndPageSpecifier) {
    var myPage, myPageAdjust;
    app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;

    //Save the old page numbering
    var myOldPageNumbering = app.generalPreferences.pageNumbering;
    app.generalPreferences.pageNumbering = PageNumberingOptions.section;
    var myStartPage = resolve(myStartPageSpecifier);
    var myEndPage = resolve(myEndPageSpecifier);
    //Set page numbering to absolute
    app.generalPreferences.pageNumbering = PageNumberingOptions.absolute;
    //Does the document start with an even page?
    if (myCheckPageStart(app.activeDocument) == false) {
        myPageAdjust = 0;
    }
    else {
        myPageAdjust = 1;
    }
    for (var myCounter = (myStartPage.documentOffset); myCounter <= myEndPage.documentOffset; myCounter++) {
        myPage = app.activeDocument.pages.item(myCounter);
        var myPageValue = myPage.documentOffset;
        myPageValue = myPageValue + myPageAdjust;
        if (myPageValue % 2 == 0) {
            //Page is an even page.
            myAdjustPage(myPage, myEvenX, myEvenY);
        }
        else {
            //Page is an odd page.
            myAdjustPage(myPage, myOddX, myOddY);
        }
    }
    app.generalPreferences.pageNumbering = myOldPageNumbering;
}
function myAdjustPage(myPage, myX, myY) {
    var myPageItem;
    var myResetItemLock = false;
    var myResetLayerLock = false;
    for (var myCounter = 0; myCounter < myPage.pageItems.length; myCounter++) {
        myPageItem = myPage.pageItems.item(myCounter);
        if (myPageItem.locked == true) {
            myPageItem.locked = false;
            myResetItemLock = true;
        }
        if (myPageItem.itemLayer.locked == true) {
            myPageItem.itemLayer.locked = false;
            myResetLayerLock = true;

        }
        myPageItem.move(undefined, [myX, myY]);
        if (myResetItemLock == true) {
            myPageItem.locked = true;
        }
        if (myResetLayerLock == true) {
            myPageItem.itemLayer.locked = true;
        }
    }
}
function myGetPageSpecifiers() {
    var myPageSpecifiers = new Array;
    for (myCounter = 0; myCounter < app.activeDocument.pages.length; myCounter++) {
        myPageSpecifiers.push(app.activeDocument.pages.item(myCounter).toSpecifier());
    }
    return myPageSpecifiers;
}
function myCheckPageStart(myDocument) {
    var mySection = myDocument.sections.item(0);
    if (mySection.pageNumberStart % 2 == 0) {
        //Starting page number is an even page.
        return false;
    }
    else {
        //Starting page number is an odd page.
        return true;
    }
}
function myCheckPageRange(myStartPageSpecifier, myEndPageSpecifier) {
    var myStartIndex = resolve(myStartPageSpecifier).documentOffset;
    var myEndIndex = resolve(myEndPageSpecifier).documentOffset;
    if (myStartIndex <= myEndIndex) {
        return true;
    }
    else {
        return false;
    }
}


app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Adjust Layout');

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

Any chance we can also move objects in master pages with this script? That would be great.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 28, 2022 Apr 28, 2022

Copy link to clipboard

Copied

Do you mean if you created a new master page, and then the *master pages* were out-of-phase in terms of being left-right pages of spread? But I suspect I don't understand what you mean correctly. In a normal set up you'd have a limited number of master pages and they'd be best updated manually.

 

It would help if you explained (exactly) how your document is constructed and what (exactly) you'd need to do to the master pages. In any case it would be a larger modification to the script than I made.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 28, 2022 Apr 28, 2022

Copy link to clipboard

Copied

My document is set up like this.  I mean the ability to move everything on all master pages. (Now script only moves everything on normal pages only.) Its not that important but It would be nice to have that option. 

AhmetSamsa_1-1651184877283.png

 

AhmetSamsa_0-1651184864506.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 28, 2022 Apr 28, 2022

Copy link to clipboard

Copied

Okay, but how would the script know which master pages to move left and which to move right? Or are they in left/right/left/right order already?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 28, 2022 Apr 28, 2022

Copy link to clipboard

Copied

Oh, good question. When I create Master Page, I set the number of pages for the master page to 1. So I don't know if they are on the left or right side. I could share InDesign file, if that's going to help.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 28, 2022 Apr 28, 2022

Copy link to clipboard

Copied

@m1b  The script also moves everything 2-3x more.  I tested with .points measurement also with millimeters by changing the code. Instead of moving "1 mm" to left, its moves "2.835 mm"

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 28, 2022 Apr 28, 2022

Copy link to clipboard

Copied

There are 2.835 pts in a mm, so there is incorrect unit specification. I tested the code as it is and couldn't reproduce this problem. You'll have to show us what you changed the code to I think.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 28, 2022 Apr 28, 2022

Copy link to clipboard

Copied

@m1b  I changed everything from "editUnits: MeasurementUnits.points" to "editUnits: MeasurementUnits.MILLIMETERS".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 28, 2022 Apr 28, 2022

Copy link to clipboard

Copied

LATEST

You just overdid the changes so you were getting millimeters of millimeters (a double conversion). See my updated script above. Notice that I've kept the scriptPreferences.measurementUnits as points. This is because most operations default to points and I think it's easiest to stick with points.

Also I removed all the viewPreference changing stuff because it's better to use scriptPreferences as they only affect scripts and won't change anything in your document.

- Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines