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

script to detect overset text not working on grouped text boxes

Advisor ,
Dec 13, 2018 Dec 13, 2018

Copy link to clipboard

Copied

Hello,

I have been using the below code found on this forum a while ago in some scripts used to exporting pdfs, It was just recently discovered that the portion code looking for overset text doesn't work if a text box containing overset text is grouped with another. Any help would be greatly appreciated!

doc = app.documents[0];

var mExitFlag = false; 

 

var mTextFrames = doc.textFrames; 

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

    if (mTextFrames.parentStory.overflows && checkIfOnPage(mTextFrames) && mTextFrames.itemLayer.visible == true){ 

        alert('Document Contains Overset Text, Job Aborted!')

        mExitFlag = true;

        if(mExitFlag){     

        exit();     

    } 

var mLinks = doc.links; 

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

    if ((mLinks.status == LinkStatus.LINK_MISSING || mLinks.status == LinkStatus.LINK_OUT_OF_DATE) && checkIfOnPage(mLinks.parent.parent) && mLinks.parent.parent.itemLayer.visible == true ){ 

        alert('Missing or Modified links, Job Aborted!');

        mExitFlag = true;    

        if(mExitFlag){     

        exit();     

    } 

 

 

function checkIfOnPage(mItem){      

    var _OldZeroPoint = app.activeDocument.zeroPoint;     

    app.activeDocument.zeroPoint = [0,0];     

     

    var _Width =app.activeDocument.documentPreferences.pageWidth;     

    var _Height=app.activeDocument.documentPreferences.pageHeight;     

      

    var _Bounds = mItem.geometricBounds;     

     

    if ((_Bounds[3] < 0)  || (_Bounds[1] > _Width) || (_Bounds[0] > _Height) || (_Bounds[2] < 0)){     

        return false     

    }else{     

        return true     

    }     

    app.activeDocument.zeroPoint =_OldZeroPoint;     

}

Thanks in advance!

Mike

TOPICS
Scripting

Views

2.0K

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 , Dec 13, 2018 Dec 13, 2018

mikeb41294032  wrote

 

…It was just recently discovered that the portion code looking for overset text doesn't work if a text box containing overset text is grouped with another. …

Hi Mike,

did you also discover why that's the case?

Answer: document.textFrames will only discover text frames that are not nested in groups or are not anchored or anyhow nested in deeper structures like pasted inside graphic frames etc.pp.

 

Instead of text frames better check overset on all stories of a doc

...

Votes

Translate

Translate
Community Expert ,
Dec 13, 2018 Dec 13, 2018

Copy link to clipboard

Copied

mikeb41294032  wrote

 

…It was just recently discovered that the portion code looking for overset text doesn't work if a text box containing overset text is grouped with another. …

Hi Mike,

did you also discover why that's the case?

Answer: document.textFrames will only discover text frames that are not nested in groups or are not anchored or anyhow nested in deeper structures like pasted inside graphic frames etc.pp.

 

Instead of text frames better check overset on all stories of a document. That would get any overset text frame or even overset text paths.

Also in deeply nested structures.

 

Important Note:

There could be also overset text cells in tables and overset in footnotes text.

 

Try something like the code below.

Be aware, that this code will not check overset in text cells and footnotes.

That would require way more code.

 

The if statement below also checks if the text frame or the text path is on an invisible layer or if it is "positioned on a page"*. Only if all three checks return true the code immediately below is executed.

 

*FWIW: The check if a text frame is positioned on a page can be done with your old method. But also note that your used method is not bullet proof at all. That would require a discussion of its own. One example: Geometric bounds of a frame or a text path are no proof that the rendered text of that frame is totally inside that bounds.

 

var doNotExport = false ;

var allStoriesArray = app.documents[0].stories.everyItem().getElements();


for( var n=0; n<allStoriesArray.length; n++ )

{

    var currentStory =  allStoriesArray[n];

    var textContainersLength = currentStory.textContainers.length;

    var lastFrameOfStory = currentStory.textContainers[ textContainersLength-1 ];

  

    if( currentStory.overflows && lastFrameOfStory.itemLayer.visible && lastFrameOfStory.parentPage != null )

    {

        alert( "Document Contains Overset Text, Job Aborted!" );

        doNotExport = true ;

    }

};


if( doNotExport ){ exit() }; // Or whatever routine you use to prevent the script to do further things.

alert("Job continues.");

 

Regards,
Uwe Laubender

( Adobe Community Expert )

 

EDITED: The code above was damaged when this thread was moved over to the new Adobe InDesign forum in November 2019. Edited the code. Did not test it.

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
Advisor ,
Dec 15, 2018 Dec 15, 2018

Copy link to clipboard

Copied

I was doing some testing with overset text on a path and the script gives the error below........I looked over the code and can't see any apparent issue.

Screen Shot 2018-12-15 at 8.26.27 AM.png

Thanks in advance!

Mike

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 ,
Dec 15, 2018 Dec 15, 2018

Copy link to clipboard

Copied

Hi Mike,

The issue is that the TextPath object does not contain the itemLayer property and not even the parentPage property. We would have to use the parent of TextPath to access these properties. Change the if to the following and it should hopefully work

var objToCheck = lastFrameOfStory

if(lastFrameOfStory.constructor.name == "TextPath")

     objToCheck = lastFrameOfStory.parent

if( currentStory.overflows && objToCheck.itemLayer.visible && objToCheck.parentPage != null ) 

     alert( "Document Contains Overset Text, Job Aborted!" ); 

     doNotExport = true ; 

}

Laubender​ please add if i have still missed something. I suppose this was what you intended.

Thanks,

-Manan

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
Advisor ,
Dec 15, 2018 Dec 15, 2018

Copy link to clipboard

Copied

Thank you Manan!

Its now working in all scenarios......text frames, Text paths, grouped or ungrouped.

Thanks again!

Mike

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
Advisor ,
Dec 18, 2018 Dec 18, 2018

Copy link to clipboard

Copied

Hello,

I would like to display each page# in a single alert message that contains overset text. I can only seem to return one page at a time.

It would look something like this.........................Error! Document Contains Overset Text on page(s):.......1,2,3,7,10....etc.

What would be ones approach to achieve this?

​

​

​var doc = app.documents[0];

var allStoriesArray = app.documents[0].stories.everyItem().getElements();

for(var n=0; n<allStoriesArray.length; n++){

    var currentStory =  allStoriesArray;

    var textContainersLength = currentStory.textContainers.length;

    var lastFrameOfStory = currentStory.textContainers[textContainersLength-1];

    var objToCheck = lastFrameOfStory

      

     if(lastFrameOfStory.constructor.name == "TextPath")

     objToCheck = lastFrameOfStory.parent

     if(currentStory.overflows && objToCheck.itemLayer.visible && objToCheck.parentPage != null){

     var myResult = objToCheck.parentPage.name;

     alert( "Error!\nDocument Contains Overset Text on page(s): " +myResult);

     //exit ();  

          }

    }

​

​

​

Thanks in advance!

Mike

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
Contributor ,
Dec 18, 2018 Dec 18, 2018

Copy link to clipboard

Copied

Hi Mike,

try this

var doc = app.documents[0];

var myResult = new Array;

var allStoriesArray = app.documents[0].stories.everyItem().getElements();

for(var n=0; n<allStoriesArray.length; n++){

    var currentStory =  allStoriesArray;

    var textContainersLength = currentStory.textContainers.length;

    var lastFrameOfStory = currentStory.textContainers[textContainersLength-1];

    var objToCheck = lastFrameOfStory;    

    if(lastFrameOfStory.constructor.name == "TextPath")

    objToCheck = lastFrameOfStory.parent

    if(currentStory.overflows && objToCheck.itemLayer.visible && objToCheck.parentPage != null)

        {myResult.push(objToCheck.parentPage.name);}

    }

if (myResult.length > 0)

    {alert("Error!\nDocument Contains Overset Text on page(s): \r" + myResult);}

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
Advisor ,
Dec 18, 2018 Dec 18, 2018

Copy link to clipboard

Copied

It works, Thank you!..............Ha, I was on the right track with one of my attempts trying "myResult.push(objToCheck.parentPage.name);".

Question? why does the order when the frame or path is created effect the way the page order appears in the alert message?

Below are messages from three different examples.

Screen Shot 2018-12-18 at 5.31.58 PM.pngScreen Shot 2018-12-18 at 5.59.18 PM.png

Screen Shot 2018-12-18 at 6.02.24 PM.png

Thanks again!

Mike

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
Contributor ,
Dec 18, 2018 Dec 18, 2018

Copy link to clipboard

Copied

Hi,

I don't have a clue why this happens but the numbers can be sorted in ascending order with the sort() method

if (myResult.length > 0)

     {

          myResult.sort(function(a,b) {return a-b});

          alert("Error!\nDocument Contains Overset Text on page(s): \r" + myResult);

     }

Greetings

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 ,
Dec 18, 2018 Dec 18, 2018

Copy link to clipboard

Copied

Hi Mike,

The order is effected because we loop over the stories text containers and then check whether they are overset or not and if they are only then we query for its page name. Hence the order in which the pages would be shown would depend upon the order that we get for the stories collection. So if you need page name in order you could use the sort method as suggested by fragmichnicht

-Manan

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 ,
Dec 18, 2018 Dec 18, 2018

Copy link to clipboard

Copied

Also the code above by fragmichnicht would display the pageno multiple times if a single page has multiple instances of overset text. You could avoid it using the following

var doc = app.documents[0]; 

var myResult = {}; 

var allStoriesArray = app.documents[0].stories.everyItem().getElements();  

for(var n=0; n<allStoriesArray.length; n++)

    var currentStory =  allStoriesArray;  

    var textContainersLength = currentStory.textContainers.length; 

    var lastFrameOfStory = currentStory.textContainers[textContainersLength-1];   

    var objToCheck = lastFrameOfStory;     

    if(lastFrameOfStory.constructor.name == "TextPath") 

    objToCheck = lastFrameOfStory.parent 

    if(currentStory.overflows && objToCheck.itemLayer.visible && objToCheck.parentPage != null) 

          myResult[objToCheck.parentPage.name] = objToCheck.parentPage.name; 

var pageList = ""

for(var a in myResult)

     pageList += a + ","

if(pageList != "")

     alert("Error!\nDocument Contains Overset Text on page(s): \r" + pageList.substring(0, pageList.length - 1));

-Manan

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
Advisor ,
Dec 19, 2018 Dec 19, 2018

Copy link to clipboard

Copied

Awesome!!.............Thank you both!

Manan your explanation on why the pages are out of order makes perfect sense to me. While testing I also discovered the duplicate pages being displayed as well and was working on their removal......you beat me to it!

fragmichnicht and Manan

Thanks again!

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
Advisor ,
Dec 19, 2018 Dec 19, 2018

Copy link to clipboard

Copied

Hello!

I am working with the latest version of the code that addresses the page#'s being display multiple times, but I am not able to incorporate the sort in ascending order method.

Any help would be greatly appreciated!!

Thanks in advance!

Mike

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
Contributor ,
Dec 19, 2018 Dec 19, 2018

Copy link to clipboard

Copied

hi,

this should do the trick

var doc = app.documents[0];

var myResult = {};

var allStoriesArray = app.documents[0].stories.everyItem().getElements();

for(var n=0; n<allStoriesArray.length; n++)

    {

    var currentStory =  allStoriesArray;

    var textContainersLength = currentStory.textContainers.length;

    var lastFrameOfStory = currentStory.textContainers[textContainersLength-1];

    var objToCheck = lastFrameOfStory;

    if(lastFrameOfStory.constructor.name == "TextPath")

        objToCheck = lastFrameOfStory.parent

        if(currentStory.overflows && objToCheck.itemLayer.visible && objToCheck.parentPage != null)

        myResult[objToCheck.parentPage.name] = objToCheck.parentPage.name;

    }

   

    var pageList = new Array;

   

    for(var a in myResult)

        pageList.push(a);

       

    pageList.sort(function(a,b) {return a-b});

   

    if(pageList.length > 0)

        alert("Error!\nDocument Contains Overset Text on page(s): \r" + pageList); 

Greetings

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
Advisor ,
Dec 19, 2018 Dec 19, 2018

Copy link to clipboard

Copied

LATEST

Thank you fragmichnicht!

ah yes,......sort is an array method.

Regards

Mike

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 ,
Dec 16, 2018 Dec 16, 2018

Copy link to clipboard

Copied

Hi Mike,

very good to test my code with a text path.

Hi Manan,

thank you for the additional check!

Regards,
Uwe

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 ,
Dec 13, 2018 Dec 13, 2018

Copy link to clipboard

Copied

You could add this simple piece of code right above 'var mExitFlag = false;':

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

   doc.groups.ungroup();

}

it's basically a dirty way, not necessarily to best way, to accomplish your goal and it will ungroup all group items in your document before executing the remainder of the script.

EDIT: Uwe's solution is probably better.

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
Advisor ,
Dec 13, 2018 Dec 13, 2018

Copy link to clipboard

Copied

Benreyn,

your suggestion can be dangerous!!.......I've seen in some cases where up-grouping items can cause certain effects to be lost.

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

   doc.groups.ungroup();

}

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 ,
Dec 14, 2018 Dec 14, 2018

Copy link to clipboard

Copied

mikeb -

I did say it was a dirty solution.

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 ,
Dec 13, 2018 Dec 13, 2018

Copy link to clipboard

Copied

Hi Mike,

As Uwe rightly pointed the issue was with using the doc.textFrames collection. I had also modified your code to work with groups. You can give it a try, but the cases Uwe mentioned would probably hold with my version as well

var doc = app.documents[0];

checkOverset(doc.allPageItems)

function checkOverset(tfArray)

{

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

     {

          if(tfArray.constructor.name != "TextFrame")

               continue;

          if(tfArray.parentStory.overflows && checkIfOnPage(tfArray) && tfArray.itemLayer.visible == true)

          {

               alert('Document Contains Overset Text, Job Aborted!') 

               exit();    

          }

     }

}

var mLinks = doc.links;

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

{

    if ((mLinks.status == LinkStatus.LINK_MISSING || mLinks.status == LinkStatus.LINK_OUT_OF_DATE) && checkIfOnPage(mLinks.parent.parent) && mLinks.parent.parent.itemLayer.visible == true )

    {

        alert('Missing or Modified links, Job Aborted!'); 

        exit();

    }

}

function checkIfOnPage(mItem)

{     

    var _OldZeroPoint = app.activeDocument.zeroPoint;    

    app.activeDocument.zeroPoint = [0,0];    

    var _Width =app.activeDocument.documentPreferences.pageWidth;    

    var _Height=app.activeDocument.documentPreferences.pageHeight;    

    var _Bounds = mItem.geometricBounds;

    if ((_Bounds[3] < 0)  || (_Bounds[1] > _Width) || (_Bounds[0] > _Height) || (_Bounds[2] < 0))

        return false    

    else   

        return true         

    app.activeDocument.zeroPoint =_OldZeroPoint;    

}

-Manan

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
Advisor ,
Dec 13, 2018 Dec 13, 2018

Copy link to clipboard

Copied

Thank you Manan!!

this is another useful 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
Community Expert ,
Dec 14, 2018 Dec 14, 2018

Copy link to clipboard

Copied

Hi Manan,

a little better would be using visibleBounds instead of geometricBounds.

And without setting the document's viewPreferences.rulerOrigin to RulerOrigin.SPREAD_ORIGIN you'd get into trouble with facing pages documents. But as I already said, this requires a discussion of its own.

Regards,
Uwe

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 ,
Dec 14, 2018 Dec 14, 2018

Copy link to clipboard

Copied

Thanks for pointing these out Uwe, these issues were present in the original script that i used as a base for my edits. I did not look into the portions that the OP mentioned were working fine. Just tweaked the part that was causing issues to the OP. However your suggestions make total sense

Thanks

-Manan

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
Advisor ,
Dec 13, 2018 Dec 13, 2018

Copy link to clipboard

Copied

Thank you Uwe!

and yes, I found your comments on another post for this..........

Mark overset text frame with tag

(with doc.textFrames you would not find nested text frames (grouped, pasted inside or anchored ones).

Thanks again

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