Skip to main content
runew73276507
Known Participant
February 10, 2016
Answered

Script who checks - and stop - if text has overset

  • February 10, 2016
  • 2 replies
  • 4260 views

In this script:

    var doc = app.activeDocument;    

    var mItems=doc.allPageItems;    

    var len = mItems.length;    

      

    // save measurement unit & set measurement unit to mm  

    //savedUnits = app.scriptPreferences.measurementUnit;  

    //app.scriptPreferences.measurementUnit = MeasurementUnits.MILLIMETERS;  

      

    while(len--){    

        var mItem = mItems[len];    

        var mBounds = mItem.geometricBounds;    

        var mX = getRound(mBounds[1],3);    

        var mY= getRound(mBounds[0],3);    

        

        // fit content 

        if(mX == 10 && mY == 10){   

            mItem.fit(FitOptions.CONTENT_TO_FRAME);  

        }

        if(mX == 6.999 && mY == 4.801){  

            resizeItem(mItem, 240,340)  

            mItem.move([10, 10]);  

            mItem.fit(FitOptions.CONTENT_TO_FRAME);

        }    

    } 

var doc = app.activeDocument;

var _PDFfile = new File('\\\\C:/test\\' + app.activeDocument.name.replace (/\.indd$/, '.pdf'));

var _PDFExportPreset = app.pdfExportPresets.item('MyJobOptionName'); 

if (_PDFExportPreset == null){

   alert('PDF Export Presets not found');

   exit();

    }  

    app.pdfExportPreferences.pageRange = PageRange.ALL_PAGES;                    

    doc.exportFile(ExportFormat.pdfType, _PDFfile, false,_PDFExportPreset);  

      

    /* round */    

    function getRound(number, digits) {    

            digits = (digits) ? Math.pow(10, digits) : 1000;      

            return Math.round(number * digits) / digits;      

    }   

    /* resize object */   

    function resizeItem(mItem, mWidth,mHeight) {  

        mBounds = mItem.geometricBounds;  

        mBounds[3] = mBounds[1] + mWidth;  

        mBounds[2] =mBounds[0] + mHeight;  

        mItem.geometricBounds = mBounds;   

    }

I also need the script to check for overset text.

So something like this.

1. If there is a textbox with overset text the scipt shall stop all further actions in the script and warn about it.

2. If there is no textbox with overset text the script shall just run with all actions.

This topic has been closed for replies.
Correct answer Ronald63

Hi,

Paste this snippet at the beginning of your code ...

var doc = app.activeDocument; 

var mTextFrames = doc.textFrames;

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

    if (mTextFrames.parentStory.overflows){

        alert('Overset TextFrames detected' );

        exit();

    }

}

2 replies

Loic.Aigon
Brainiac
February 10, 2016

[CS3 Notice update]

Oh ok, I wrote this post without knowledge of your CS3 notice. So it's helpless as doScript is only available for CS4+.

Loic

depends if the overflowing check has to be done before any action or can be the consequence of intial script actions. I think it's the second case given that you resize objects.

So here, you would probably want to undo previous operations if script couldn't proceed due to overflowing

var main = function(){

    var doc, pis, pi, n = 0,

    mItem,

    mBounds,

    mX,

    mY,

    _PDFExportPreset = app.pdfExportPresets.item('MyJobOptionName');

  

    if (!app.documents.length) return;

  

    /*

    if ( !_PDFExportPreset.isValid) {

        alert("Unable to find PDF preset");

        return;

    }*/

    doc = app.activeDocument;

    pis = doc.allPageItems,

    n = pis.length;

  

  

    while ( n-- ) {

        pi = pis;

      

        mBounds = pi.geometricBounds;     

        mX = getRound(mBounds[1],3);     

        mY= getRound(mBounds[0],3);     

         

        // fit content  

        if(mX == 10 && mY == 10){    

            pi.fit(FitOptions.CONTENT_TO_FRAME);   

        } 

        if(mX == 6.999 && mY == 4.801){   

            resizeItem(pi, 240,340)   

            pi.move([10, 10]);   

            pi.fit(FitOptions.CONTENT_TO_FRAME);

        }     

  

        if ( pi.constructor.name == "TextFrame"

        && pi.parentStory.overflows ) {

            throw new Error("overflow");

        }

    }

    //makePDF(doc, _PDFExportPreset);

}

var doc = app.activeDocument; 

var makePDF = function(doc, preset) {

     var _PDFfile = new File('\\\\C:/test\\' + doc.name.replace (/\.indd$/, '.pdf')); 

    app.pdfExportPreferences.pageRange = PageRange.ALL_PAGES;                     

    doc.exportFile(ExportFormat.pdfType, _PDFfile, false,preset);

}

/* round */     

function getRound(number, digits) {     

        digits = (digits) ? Math.pow(10, digits) : 1000;       

        return Math.round(number * digits) / digits;       

}    

/* resize object */    

function resizeItem(mItem, mWidth,mHeight) {   

    mBounds = mItem.geometricBounds;   

    mBounds[3] = mBounds[1] + mWidth;   

    mBounds[2] =mBounds[0] + mHeight;   

    mItem.geometricBounds = mBounds;    

var u;

try {

app.doScript("main();",u,u,UndoModes.ENTIRE_SCRIPT);

}

catch(err){

    app.documents.length && app.activeDocument.undo();

  

}

HTH

Loic

http://www.ozalto.com

runew73276507
Known Participant
February 10, 2016

I am a little confused - I need the script to warn if text has overset and then stop exporting PDF etc.

And this script you made does not work for CS3?

Brainiac
February 16, 2016

Can you help me with that extra function?

And if there is a missing or not updated link on a hidden layer - can it ignore that like it works with the textlayer:

mTextFrames.itemLayer.visible == true){


mLinks.parent.parent.itemLayer.visible == true

runew73276507
Known Participant
February 10, 2016

By the way - its for InDesign CS3