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

Trying to Move all Items (text and Graphics) on left Pages to Specific Space Not Working

Enthusiast ,
May 04, 2021 May 04, 2021

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]);
       }
       }
   }
}
}
}
}
}
}

 

 

 

 

Best
Mohammad Hasanin
TOPICS
Scripting

Views

436

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 , May 04, 2021 May 04, 2021

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

...

Votes

Translate

Translate
Community Expert ,
May 04, 2021 May 04, 2021

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.

 

Best regards

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
Enthusiast ,
May 05, 2021 May 05, 2021

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.

 

Best
Mohammad Hasanin

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 ,
May 05, 2021 May 05, 2021

Copy link to clipboard

Copied

LATEST

That's good and then we can expect these errors.. 🙂

Best regards

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