Skip to main content
Participant
January 31, 2011
Answered

delete textframes on every page, depending on it's size

  • January 31, 2011
  • 1 reply
  • 599 views

Hello!

I've got an catalogue to change, with 500 pages that contains on every page a textframe on the same position with the same size.

I want to delete this paricular textframe on every page.

How can I start ?

Many thanks for help

Regards

Martin

This topic has been closed for replies.
Correct answer Harbs.

Ok, I got it to work:

var doc = app.activeDocument;
doc.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;
doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;
var tFrames = doc.pages[0].textFrames; 
for (var n = tFrames.length-1; n >= 0 ; n--)
{         
      var gb = tFrames.geometricBounds;    
     var w = gb[3]-gb[1];       
     var h = gb[2]-gb[0];            
     if (h == 20  && w == 20 )
     {          tFrames.remove();     }
     }

Now I have to look how to loop through pages.

thx.

Martin


Keep in mind what I wrote about rounding errors, but here's the idea:

function removePageFrames(page){
  var tFrames = page.textFrames; 
  for (var n = tFrames.length-1; n >= 0 ; n--){         
    var gb = tFrames.geometricBounds;
    var w = gb[3]-gb[1];       
    var h = gb[2]-gb[0];            
    if (h == 20  && w == 20 ){
      tFrames.remove();
    }
  }
}
for(var i=0;i<doc.pages.length;i++){
 
removePageFrames(doc.pages);
}

1 reply

Harbs.
Legend
January 31, 2011

Loop through the text frames and check their geometricBounds. If the bounds fit the frame location remove() the frame...

(Include the inner loop inside an outer loop which loops through all pages in the doc...)

Harbs

Participant
January 31, 2011

Hello Harbs.

I got this part of code, but it does not work.

var doc = app.activeDocument;

var tFrames = doc.pages[0].textFrames;

for (var n = tFrames.length-1; n >= 0 ; n--) {
    
    var gb = tFrames.geometricBounds;
    var w = gb[3]-gb[1];    
    var h = gb[2]-gb[0];    
    
    if (h == 20 && w == 20){ 
        tFrames.remove();
    }
}

Can you imagine, what is wrong?

/Edit: the size is in mm ----> could that be the mistake?

Thanks

Martin

Harbs.
Legend
January 31, 2011

Two things:

1) Yes. Make sure your measurement units are correct.

2) Due to rounding errors do not check for exact values.

try something like this:

if (h > 19 && h < 21 && w > 19 && w < 21){  
        tFrames.remove();
    }

Harbs