Copy link to clipboard
Copied
Hi Experts, I have a problem in my code (not Working) it shouid work in left hand pages but it work on all document, , no error messages, i updated the code , Im trying to move all left hand pages items only -5 mm including text frames and other graphic elements, maybe i missing something :
function LPDocShifter() {
var allDocPages = app.documents[0].pages.everyItem().getElements();
// Loop all pages:
for( var n=0; n<allDocPages.length; n++ )
{
// Test Left Hand side of page:
if( allDocPages[n].side == PageSideOptions.LEFT_HAND )
// Get all items on the current page:
var allPageItemsOfThatPage = allDocPages[n].allPageItems;
for( var i = 0; i<allPageItemsOfThatPage.length; i++ )
{
{
if(allPageItemsOfThatPage[i].constructor.name == "TextFrame" ) {
if(allPageItemsOfThatPage[i].constructor.name == "Rectangle" ) {
if(allPageItemsOfThatPage[i].constructor.name == "Oval" ) {
if(allPageItemsOfThatPage[i].constructor.name == "Polygon" ) {
if(allPageItemsOfThatPage[i].getElements()[0].contentType == ContentType.GRAPHIC_TYPE){
//app.documents[0].pages[n].pageItems.everyItem().move( undefined , [ "-5 mm" , "0 mm"] );
var myLPage = allDocPages.pages[n].pageItems.everyItem().getElements();
myLPage.move([-5,0]);
}
}
}
}
}
}
}
}
}
HI,
There are lots of mistake in your code.
1. First is curly braces missing or extra. For ane example in the following line
if( allDocPages[n].side == PageSideOptions.LEFT_HAND )
curly braces is missing to make it a block.
2. Second your logic inside the if statement is not correct. The way you are checking is if allPageItemsOfThatPage[i] is TextFrame then go inside, and inside this if there is another if statement which check whether allPageItemsOfThatPage[i] is a Rectangle or not. These sta
...Copy link to clipboard
Copied
HI,
There are lots of mistake in your code.
1. First is curly braces missing or extra. For ane example in the following line
if( allDocPages[n].side == PageSideOptions.LEFT_HAND )
curly braces is missing to make it a block.
2. Second your logic inside the if statement is not correct. The way you are checking is if allPageItemsOfThatPage[i] is TextFrame then go inside, and inside this if there is another if statement which check whether allPageItemsOfThatPage[i] is a Rectangle or not. These staments means if object is textframe then go inside, an if object is textframe how it will be Rectangle?There are nested if which will never be true. Therefore main logic to move item by -5 will never gets executed.
Correct version of the script will be
function LPDocShifter() {
var allDocPages = app.documents[0].pages.everyItem().getElements();
// Loop all pages:
for (var n = 0; n < allDocPages.length; n++) {
// Test Left Hand side of page:
if (allDocPages[n].side == PageSideOptions.LEFT_HAND) {
// Get all items on the current page:
var allPageItemsOfThatPage = allDocPages[n].allPageItems;
for (var i = 0; i < allPageItemsOfThatPage.length; i++) {
if (allPageItemsOfThatPage[i].constructor.name == "TextFrame" || allPageItemsOfThatPage[i].constructor.name == "Rectangle" || allPageItemsOfThatPage[i].constructor.name == "Oval" || allPageItemsOfThatPage[i].constructor.name == "Polygon" || (allPageItemsOfThatPage[i].constructor.name == "Rectangle" && allPageItemsOfThatPage[i].contentType == ContentType.GRAPHIC_TYPE)) {
var myLPage = allPageItemsOfThatPage[i];
myLPage.move([-5, 0]);
}
}
}
}
}
LPDocShifter()
I hope this is what you are looking for. Please compare your version of teh script with mine to understand the mistake in logic.
Copy link to clipboard
Copied
Dear Charu Rajput
Thanks a lot, execuse me i'm still learning coding in Javascript, and i learn a lot today.
Copy link to clipboard
Copied
That's good and then we can expect these errors.. 🙂