Copy link to clipboard
Copied
Hi Scripter ...new question starting from here:
var mySelection = app.activeDocument.selection[0].geometricBounds;
//alert (mySelection);
everywhere in the document i need to find and remove text frames with the same geometricBounds.
If possible, same dimensions but not same positions.
Thanks for help!
ok Bala ...due to decimal differences some frames weren't removed.
I solved with "Math.round" in place of "Number"
===================
var mySelection = app.activeDocument.selection[0].geometricBounds;
var myWidth = Math.round(mySelection[3]-mySelection[1]);
var myHeight = Math.round(mySelection[2]-mySelection[0]); alert(myHeight);
var allFrames = app.activeDocument.allPageItems;
while(t = allFrames.pop() ) {
if(t.isValid){
var myTextframe = t.geometricBounds;
var
...Copy link to clipboard
Copied
Hi,
According to my understanding, frame which having the equal widthxheight need to be remove, sorry if it’s not match your requirement.
============================
var mySelection = app.activeDocument.selection[0].geometricBounds;
var myWidth = Number(mySelection[3]-mySelection[1]);
var myHeight = Number(mySelection[2]-mySelection[0]);
var allFrames = app.activeDocument.allPageItems;
while(t = allFrames.pop() ) {
if(t.isValid){
var myTextframe = t.geometricBounds;
var myTWidth = Number(myTextframe[3]-myTextframe[1]);
var myTHeight = Number(myTextframe[2]-myTextframe[0]);
if((myWidth == myTWidth) && (myHeight == myTHeight)){
t.remove();
}
}
}
===================
Regards,
Bala
Copy link to clipboard
Copied
Thanks Bala, this is exactly what i mean ...but testing the script (indesign cs6) something is going wrong.
Not all frames (with same dimensions) are removed.
Have a better situation using "parseInt" instead of "Number".
I would join my indesign test document but don't know how.
Anyway, this is great for me, good to work around
best regards
Copy link to clipboard
Copied
ok Bala ...due to decimal differences some frames weren't removed.
I solved with "Math.round" in place of "Number"
===================
var mySelection = app.activeDocument.selection[0].geometricBounds;
var myWidth = Math.round(mySelection[3]-mySelection[1]);
var myHeight = Math.round(mySelection[2]-mySelection[0]); alert(myHeight);
var allFrames = app.activeDocument.allPageItems;
while(t = allFrames.pop() ) {
if(t.isValid){
var myTextframe = t.geometricBounds;
var myTWidth = Math.round(myTextframe[3]-myTextframe[1]);
var myTHeight = Math.round(myTextframe[2]-myTextframe[0]);
if((myWidth == myTWidth) && (myHeight == myTHeight)){
t.remove();
}
}
}
===================
Now your script works fine!
Thanks a lot!
Copy link to clipboard
Copied
Hi,
I am trying to find and move text frames from one position to another. Below is the code I tried. I am using Indesign CS6, and nothing happened when this script was running. Can you please help me on this. Thanks.
var oldposition = [216.425, 103.89] // original position, upper left corner
var newposition = [216.425, 54] // new position, upper left corner
//var threshold = new UnitValue(1,"pt"); // threshold value
var myFrame = app.activeDocument.textFrames.everyItem().getElements();
for (var i=0; i<myFrame.length; i++){
// if (Math.abs(myFrame.geometricBounds[1]-oldposition[0])<threshold &&Math.abs(myFrame.geometricBounds[0]-oldposition[1])<threshold ){
if (Math.round(myFrame.geometricBounds[1])==oldposition[0]&&Math.round(myFrame.geometricBounds[0])==oldposition[1]){
myFrame.move(newposition);
}
}
Copy link to clipboard
Copied
i tried to tweak the script a little to make multiple items selection instead of only one and move to new position, its working fine when selecting different size items, the problem is when selecting two items or more that matches the geometric bounds (match size) its repeat the move for twice!, can expert tell me how to select multiple items at once without repeating the move! i mean with correcting the script below :
function AdjustPosition(){
var allSelecteditems = app.selection;
for (var i = 0; i < allSelecteditems.length; i++) {
var mySelection = allSelecteditems[i].geometricBounds;
//y1 x1 y2 x2
//[0] [1] [2] [3]
var X1 = mySelection[1];
var Y1 = mySelection[0];
var X2 = mySelection[3];
var Y2 = mySelection[2];
//my Width and Hieght
var myWidth = Math.round(X2-X1);
var myHeight = Math.round(Y2-Y1);
var allDocFrames = app.activeDocument.pages.everyItem().pageItems.everyItem().getElements();
var myCollectedFrames =[];
while(myMatchedFrames = allDocFrames.pop() ) {
if(myMatchedFrames.isValid){
var myMatchframe = myMatchedFrames.geometricBounds;
var myTWidth = Math.round(myMatchframe[3]-myMatchframe[1]);
var myTHeight = Math.round(myMatchframe[2]-myMatchframe[0]);
if((myWidth == myTWidth) && (myHeight == myTHeight)){
myCollectedFrames.push(myMatchframe); //Adding to Array the Frame that Will be Processed
myMatchedFrames.move(undefined , [0 ,"10mm"]); //0 is X , other is Y
}
}
}
}
alert("Done!, "+myCollectedFrames.length+" Frames (All Same Size) Moved!","Finished" );
}
app.doScript(AdjustPosition, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Adjust Same Size Frames Positions");