Copy link to clipboard
Copied
I had written an applescript that will find overset text boxes, and tried and fix them (if the text box expanded to far into another it wouldn't fix it). now I'm trying to do it in Javascript. I was able to write some code that works on a normal text box. however there are some text boxes, that are in another box (bordered 1pt). The script doesn't seem to see those.
I'm guessing because its a text frame in another (bordered frame). If this is the case Im not sure how to tell the script to look into a text frame, for another tet frame that overset.
Applescript nevermade that distinction if it was over set it fixed it.
Can anybody help
1 Correct answer
Hi,
going a step further...
Since pageItem.id cannot be lower than its parent.id
- we should sort() and reverse() a textFrameIDArray to step into a safe way of interating through all textFrames to fix their overset. (safe as far as interplay of textFrames overlapping can be managed)
I mean:
...//....
textFrameIDArray.sort().reverse();
for (var k = 0; k < textFrameIDArray.length; k++)
if (myDoc.pageItems.itemByID(textFrameIDArray
).overflows) { // do something
;
Copy link to clipboard
Copied
Hi,
JonnyDL wrote:
...(if the text box expanded to far into another it wouldn't fix it). now I'm trying to do it in Javascript...
So are you hoping to fix it using Javascript instead of Applescript?
In case of anchored textFrames you have to start fixing from "youngest" child and go to its parent (parents) in next steps.
Jarek
Copy link to clipboard
Copied
Jump_over
I was hoping to see if I can improve on the script, and learn some indesign Javascript while I was at it. It appears with Javascript I have a bit more controll than applescript. With the inline texframes I'll have to experiment with the code to find the best way those (that are overset in the document and then do what I want with them.
Thanks
Copy link to clipboard
Copied
Jonny,
Two ways (maybe more) to find inline text frames ("text boxes that are in another box"). The test you choose depends on your starting point. The first is to check whether a text frame contains any text frames:
if (myTextFrame.textFrames.length > 0) {
// myTextFrame contains one or more inlines
Another test is to check whether a text frame is an inline. If it is, its parent is an object of type Character. If it isn't an inline, its parent is a Spread:
if (myTextFrames.parent instanceof Character) {
// myTextFrames is an inline
Peter
Copy link to clipboard
Copied
Peter
Thanks for the help and the correct terminology, will make it easier to find more help on what I want to do.
find overset in both inline and non inline (using the instanceof), and then make adjustments to the box and items around it base one an inline or regular text frame.
Copy link to clipboard
Copied
@Jonny – regarding scope of a script, what object it can act upon and what object is "invisible" or not reachable, ExtendScript (and also AppleScript, I think) has not an allTextFrames array.
In contrast to the allGraphics array which returns all Graphic objects, nested or not.
Or the allPageItems array, which returns nearly all page items, and of course also textFrames, which is a subclass of pageItem.
In short and missing some important details: you could loop through all page items of the allPageItems array, check, if one of the pageItems is an overset text frame and do your thing.
In ExtendScript that would be:
var myDoc = app.documents[0];
var textFrameIDArray = new Array();
//Getting the ID of text frames looping through ALL page items:
for(var n=0;n<myDoc.allPageItems.length;n++){
if(myDoc.allPageItems
.getElements()[0].constructor.name === "TextFrame"){ textFrameIDArray[textFrameIDArray.length] = myDoc.allPageItems
.id; };
};
//Looping through all Text Frames, also the nested ones:
for(var n=0;n<textFrameIDArray.length;n++){
var myCurrentTextFrame = myDoc.pageItems.itemByID(textFrameIDArray
).getElements()[0]; if(myCurrentTextFrame.overflows){
//Some dummy code here
//Sets the fill color of an overset textFrame to yellow.
doSomethingWithOverflow(myCurrentTextFrame);
};
};
function doSomethingWithOverflow(myTextFrame){
//Do YOUR thing here!
myTextFrame.fillColor = "Yellow";
};
Why would I store the ID of an TextFrame in the first loop and not doing instantly something like checking for overflow and correcting that?
Depending what you do with nesting overset text frames, it could be that correcting the overflow could generate new overset text frames and in storing the IDs of all textFrames I can come easily back like in the second loop to check for overset. Sometimes you cannot correct overset so I would not recommend a while loop running on the positive test for overset text frames present in the document.
Uwe
Copy link to clipboard
Copied
Adding some questions to all AppleScript developers:
Shouldn't there be something like allPageItems in AppleScript? Maybe a collection instead of an array? And isn't there a whose method in AppleScript? And shouldn't we be able to resolve a specifier of a given pageItem like in ExtendScript?
So theoretically would it be easier in AppleScript to get all page items whose property overflow is set to true, storing their IDs and working with that array?
Uwe
Copy link to clipboard
Copied
Hi Uwe,
Your first loop is very labour-intensive: in
for(var n=0;n<myDoc.allPageItems.length;n++)
an array of all page items is generated for every iteration of the loop and its length is computed every time. In addition, each time this clause:
if(myDoc.allPageItems
. . .
is executed, the array is created again. And finally, each time this line is processed:
textFrameIDArray[textFrameIDArray.length] = myDoc.allPageItems
.id
both the length of textFrameIDArray and allPageItems are re-computed. There's no need for all that computation:
var pItems = myDoc.allPageItems;
for (var n = pItems.length-1; i >= 0; i--) {
if (pItems
.constructor.name === "TextFrame"){ textFrameIDArray.push (pItems
.id); }
}
The array pItems is computed just once; the length of the array is computed just once by processing starting at the end; and there's no need to compute the index of the last element of the textFrameIDArray.
By the way, because myDoc.allPageItems is an array, myDoc.allPageItems
Peter
Copy link to clipboard
Copied
@Peter – oh my, yes you are right…
Thank you very much for clarification!
Uwe
Copy link to clipboard
Copied
Hi,
going a step further...
Since pageItem.id cannot be lower than its parent.id
- we should sort() and reverse() a textFrameIDArray to step into a safe way of interating through all textFrames to fix their overset. (safe as far as interplay of textFrames overlapping can be managed)
I mean:
//....
textFrameIDArray.sort().reverse();
for (var k = 0; k < textFrameIDArray.length; k++)
if (myDoc.pageItems.itemByID(textFrameIDArray
).overflows) { // do something
;
}
Jarek
Copy link to clipboard
Copied
I did something like this recently. After struggling with inset items and every possible parent-of-parent-of-parent-of... combination I could think of, I went at it another way. Stories also have an "overflows" property. The last text container of any story whose "overflows" is true is the text frame that contains the overflow.
Copy link to clipboard
Copied
I've been putting together some code from all the info I've gotten here. I've been able to locate all the overset boxes and build on the code to just about get it to do what I need it to. There is one issue I'm not sure how to fix, becuse I'm not sure what its doing.
When I use manually the overset window, select the txt frame and use the fit content to frame option it works, but when I use the fit (fit content to frame) in a script it makes a minor improvement but they still appear to be overset. I need to pull them down (height) a little more .25". Is it beause they are inline boxes (with a 1pt stroke)? I tried adding a line of code to increase the boxes height by 25", but nothing happens.
.geometricBounds is an array of the object bounds? with
myTextFrame.geometricBounds[2] I would get the bounds for item 2 (y)
using that same logic i thought I could change the bounds of the object
myTextFrame.geometricBounds[2] ="3p0"
myTextFrame.geometricBounds[3] ="3p0"
this doesn't error out, but I get no change, can you write it like that to change it, or is there another format to use (a better one just for changing its height)
Thanks (All you guys) for the help
Copy link to clipboard
Copied
Changing the value of the bounds array isn't enough: you need to apply that new array. For example:
gb = myFrame.geometricBounds;
gb[2] = '3p0';
gb[3] = '3p0';
myFrame.geometricBounds = gb;
When you're dealing with stroked frames and calculate the available space in a frame, remember that geometricBounds gives you the frame without the stroke. So if your frame has a 1pt stroke and straddles the frame's border, then to calculate the available space inside the frame, deduct 1pt from your calculated width and height.
Peter
Copy link to clipboard
Copied
I ment guys in the non gender type......but you are correct
Thank you Mary
Copy link to clipboard
Copied
> Thanks (All you guys) for the help
What about Mary?

