Copy link to clipboard
Copied
Hi Forum,
Your help is much appreciated.
I would like to check the rectangle which is the tallest of all, on each and every page, and write it in a txt file.
Here is my try. I can write only the first page rectangle height.
writeData();
function writeData (aData )
{
tt= [];
myFile = new File("/Users/astudio/Desktop/Info/rectangle.txt");
if( myFile!='' )
{
//Open the file for writing.
myResult = myFile.open( 'w', undefined, undefined );
}
rct = app.activeDocument.pages.everyItem().rectangles.everyItem().getElements();
for(i=0; i<rct.length; i++) {
rcc = rct.rectangles.everyItem().getElements()
tt.push((rct.geometricBounds[2]-rct.geometricBounds[0]));
var myarray = tt;
var tf = myarray.sort(SortLowToHigh).pop();
myFile.writeln(rct.geometricBounds[2]-rct.geometricBounds[0]);
function SortLowToHigh(a, b) {
if (a > b) return 1;
else if (a < b) return -1;
else return 0;
}
myFile.close();
continue; /// I can't able to write the maximum height of the rectangle for next next pages..... one below the other in Text file.
}
}
Please help me out to get this done.
thanks very much.
He, why don’t you use the code-editor?
To find the tallest rectangle on every page, I would do something like:
...var curDoc = app.activeDocument;
var allPages = curDoc.pages;
var list = [];
for ( var p = 0; p < allPages.length; p++ ) {
var curPage = allPages
;
var curPageRectangles = curPage.rectangles;
var theTallestHeight = curPageRectangles[0];
for ( var r = 1; r < curPageRectangles.length; r++ ) {
var curRect = curPage.rectangles
; if ( curRect.visibleBounds[2] -
Copy link to clipboard
Copied
Sorry forum a small correction
var tf = myarray.sort(SortLowToHigh).pop();
myFile.writeln(rct.geometricBounds[2]-rct.geometricBounds[0]);
However it writes all the rectangles heights and not the tallest of all.
thanks.
Copy link to clipboard
Copied
Again, forum for more Information...
I tested, it writes like this.
30.5671641790929
18.1492537313365
16
9.50000000000001
44.6567164181409
26.5149253732712
but,
page 1 rectangles height.....
30.5671641790929 // I need to write only the tallest rectangle of page 1
18.1492537313365
page 2 rectangles height
16 // I need to write only the tallest rectangle of page 2
9.50000000000001
page 3 rectangles height
44.6567164181409 // I need to write only the tallest rectangle of page 3
26.5149253732712
thanks forum.
Copy link to clipboard
Copied
He, why don’t you use the code-editor?
To find the tallest rectangle on every page, I would do something like:
var curDoc = app.activeDocument;
var allPages = curDoc.pages;
var list = [];
for ( var p = 0; p < allPages.length; p++ ) {
var curPage = allPages
;
var curPageRectangles = curPage.rectangles;
var theTallestHeight = curPageRectangles[0];
for ( var r = 1; r < curPageRectangles.length; r++ ) {
var curRect = curPage.rectangles
; if ( curRect.visibleBounds[2] - curRect.visibleBounds[0] > theTallestHeight.visibleBounds[2] - theTallestHeight.visibleBounds[0] ) {
theTallestHeight = curRect;
}
}
list.push( "Page " + theTallestHeight.parentPage.name + ": " + String( theTallestHeight.visibleBounds[2] - theTallestHeight.visibleBounds[0] ) );
}
alert ( list.join( "\r" ) );
Copy link to clipboard
Copied
Thanks for your valuable support.
Kai, I have a doubt on this. When i tried to retain only the tallest rectangle on page, deleting other. The script doesn't consider the recently added tallest rectangle.
The recently added rectangle hasn't been considered as Item(0) (curPageRectangles[0];).
Any help please.
THanks for your support on time. timely indeed.
Copy link to clipboard
Copied
Hm, sorry but I did not understand the problem … maybe some advanced scripters see something that I’m not aware of.
Assume you have 4 rectangles. The script take curDocRectangles[0] and assumes, that this one is the tallest one.
If you create a new rectangle, this new one get the index 0. So if you start the script again, this rectangle will be check at first.
So, if you have a problem with this, try to built a example, where the script goes wrong and try to describe in good english your steps.
– Kai
Copy link to clipboard
Copied
Kai, thank you so much for your extensive support.
I'm really sorry for the communication issue.
Please bear with me for the inconvenience.
I will update you, what Im trying to get from you.
thanks for the support kai.
Copy link to clipboard
Copied
Hi kai,
I'm just trying to delete all the smallest height rectangles leaving the tallest one intact.
The script edited (the one you helped me).
var curDoc = app.activeDocument;
var allPages = curDoc.pages;
var list = [];
for ( var p = 0; p < allPages.length; p++ ) {
var curPage = allPages
;
var curPageRectangles = curPage.rectangles;
var theTallestHeight = curPageRectangles[0];
for ( var r = 1; r < curPageRectangles.length; r++ ) {
var curRect = curPage.rectangles
if(curRect.visibleBounds[2] - curRect.visibleBounds[0]!=String( theTallestHeight.visibleBounds[2] - theTallestHeight.visibleBounds[0] )) {
curRect.remove();
}
}
}
As you said, Let's assume, I have 4 rectangles on each pages, with different heights.
After running the edited script (above), only 1 smallest height rectangle is deleted on all the pages.
My intention is to delete all the 3 smallest rectangle, except the 1, the tallest rectangle on each page.
Thanks for the support Kai,
Copy link to clipboard
Copied
Hi Kai,
Thanks for your help & support.
Temporarily I have found something like this. Just tweaked your script.
Please correct me if I went wrong here.
var curDoc = app.activeDocument;
var allPages = curDoc.pages;
var list = [];
for ( var p = 0; p < allPages.length; p++ ) {
var curPage = allPages
;
var curPageRectangles = curPage.rectangles;
var theTallestHeight = curPageRectangles[0];
for ( var r = 1; r<curPageRectangles.length-1; r++) {
var curRect = curPage.rectangles
if(curRect.visibleBounds[2] - curRect.visibleBounds[0]<String( theTallestHeight.visibleBounds[2] - theTallestHeight.visibleBounds[0] )) {
try {
do(curPage.rectangles
while(curPageRectangles[0]!=0 )
} catch (e) {}
}
}
}
Kai, kindly correct the above script, to do much better & prettier.
Thanks for your support Kai.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now