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

Unlock PageItem in InDesign page

Explorer ,
Oct 24, 2018 Oct 24, 2018

Copy link to clipboard

Copied

Dear All,

I have tried to override pageitems in InDesign page. In master page the textframes are threaded while I try to override master page items in the first page of the inDesign document the frame thread is broken. I want only override threaded frame in the master page. Could you anyone help me to fix this issue.

MasterPage.png

After executing script i have get the following

After.png

Here is my code

var mainFrame=getFrame(app.activeDocument.pages[0], "MainFrame");

if(mainFrame!=$.global.undefined) {

    TextFlowForINTT(mainFrame);

}

function getFrame(myPage, labelString) {

    try {

        var myTextFrames = myPage.textFrames;

        for (var i = 0; i < myTextFrames.length; i++) {

            if (myTextFrames.label.match(labelString))

                return myTextFrames;

        }

    } catch (e) {

        new MyException("getFrame ", e, errorLogFile, true)

    }

}

function TextFlowForINTT(mainFrame) {

    try {       

            var maxPageCount=0;

            var myDoc = app.activeDocument; 

            myDoc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;

            var myTextFrame = mainFrame.endTextFrame;

            var gBounds=myTextFrame.geometricBounds;

            while (myTextFrame.overflows) {

maxPageCount++;

            var newPage=myDoc.pages.add();           

            var pageIndex=myDoc.pages.length-1;

            OverrideMasterItemsOnlyForMainFrame(pageIndex,"MainFrame");

            //app.menuActions.itemByName('$ID/Override All Master Page Items').invoke();       

            var mainFrame=getFrame(newPage,"MainFrame");    

            if(mainFrame!=$.global.undefined) {

                mainFrame.label="MainFrame";

                mainFrame.previousTextFrame = myTextFrame;

                //myDoc.align(mainFrame, AlignOptions.LEFT_EDGES, AlignDistributeBounds.MARGIN_BOUNDS);

                myTextFrame = myTextFrame.endTextFrame;  

            }

if(maxPageCount>800) {

alert("overset found. script can't reflow the text into inDesign template.");

                  exit(0);

}

        }

    } catch(e) {

       

    }  

}

function OverrideMasterItemsOnlyForMainFrame(pageIndex,mainFrameLabel) { 

    try {

            var mainFrameArray=[];

            var myDocument = app.activeDocument;

            var targetPage=myDocument.pages[pageIndex];

            if(targetPage.side==PageSideOptions.LEFT_HAND) {

                var allItems = myDocument.pages[pageIndex].appliedMaster.pages[0].pageItems.everyItem().getElements();     

            }else {

                var allItems = myDocument.pages[pageIndex].appliedMaster.pages[1].pageItems.everyItem().getElements(); 

            }

           

            for(var i=0;i<allItems.length;i++){ 

                try{

                        if(allItems instanceof TextFrame&&allItems.label==mainFrameLabel) {

                          //  var newFrames = threadOverride(sourceSpread, allItems, destPage);

                            allItems.allowOverrides = true;

                            //mainFrameArray.push(allItems);

                            allItems.override(targetPage);

                        } 

                    }       

                catch(e){

                } 

            }

            //app.select(mainFrameArray);

            //app.selection[0].override(targetPage);           

            //app.selection[1].override(targetPage);

        }catch(e) {

                $.writeln(e);

        }

Thanks ,

Prakash C

this post moved to InDesign Scripting forum. (Moderator)

TOPICS
Scripting

Views

1.5K

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

Explorer , Oct 25, 2018 Oct 25, 2018

Finally I found the solution. I have used the allowOverrides option

Votes

Translate

Translate
Community Expert ,
Oct 24, 2018 Oct 24, 2018

Copy link to clipboard

Copied

Clicking on a locked Master Page item with the Shift and the Command (Mac) or the Shift and Control (PC) held will unlock just that item.

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 ,
Oct 24, 2018 Oct 24, 2018

Copy link to clipboard

Copied

Yes, But I want to do this via scripting. Is this possible?

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 ,
Oct 24, 2018 Oct 24, 2018

Copy link to clipboard

Copied

Try the InDesign Scripting Forum InDesign Scripting .

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
Participant ,
Oct 24, 2018 Oct 24, 2018

Copy link to clipboard

Copied

You should be able to over ride master page/spread items as seen here:

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#PageItem.html

allowOverrides

Boolean

read/write

If true, the master page item can be overridden.

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
Advocate ,
Oct 24, 2018 Oct 24, 2018

Copy link to clipboard

Copied

Try this,

var myPages = app.documents[0].pages;

for(var i = 0; i < myPages.length; i++){

    var item = myPages.allPageItems;

    for(var j = 0; j < item.length; j++){

        if(item.locked){

            item.locked = false;

            }

        }

    }

var myMasters = app.documents[0].masterSpreads;

for(var i = 0; i < myMasters.length; i++){

    var page = myMasters.pages;

    for(var k = 0; k < page.length; k++){

        var item = page.allPageItems;

        for(var j = 0; j < item.length; j++){

            if(item.locked){

                item.locked = false;

                }

            }

        }

    }

var myLayer = app.documents[0].layers;

for(var i = 0; i < myLayer.length; i++){

    if(myLayer.locked){

        myLayer.locked = false;

        }

    }

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 ,
Oct 24, 2018 Oct 24, 2018

Copy link to clipboard

Copied

Hi Yadav,

I tried your script also but, it doesn't fix my problem .

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 ,
Oct 25, 2018 Oct 25, 2018

Copy link to clipboard

Copied

LATEST

Finally I found the solution. I have used the allowOverrides option

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