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.
After executing script i have get the following
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)
Finally I found the solution. I have used the allowOverrides option
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.
Copy link to clipboard
Copied
Yes, But I want to do this via scripting. Is this possible?
Copy link to clipboard
Copied
Try the InDesign Scripting Forum InDesign Scripting .
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 | read/write | If true, the master page item can be overridden. |
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;
}
}
Copy link to clipboard
Copied
Hi Yadav,
I tried your script also but, it doesn't fix my problem .
Copy link to clipboard
Copied
Finally I found the solution. I have used the allowOverrides option