Copy link to clipboard
Copied
Hi All,
I am adding some text into an anchored textframe and placed in the same location using Indesign javascript.
But I am unable to fit the anchored text frame to content.
Below I have pasted the source code.
try
{
for (i = 0; i < myFound.length; i++)
{
var myInsertionPoint = myFound.insertionPoints[-1];
var myAnchoredFrame = myInsertionPoint.textFrames.add();
myAnchoredFrame.contents = "This is an anchored frame.";
myAnchoredFrame.fit(FitOptions.FRAME_TO_CONTENT);
with(myAnchoredFrame.anchoredObjectSettings)
{
anchoredPosition = AnchorPosition.anchored;
anchorPoint = AnchorPoint.topLeftAnchor;
horizontalReferencePoint = AnchoredRelativeTo.anchorLocation;
horizontalAlignment = HorizontalAlignment.leftAlign;
anchorXoffset = 72;
verticalReferencePoint = VerticallyRelativeTo.lineBaseline;
anchorYoffset = 24;
anchorSpaceAbove = 24;
}
}
}
catch (e) {alert (e.message)}
Please help me out.
Thanks in advance,
Christy
Dear Hans,
Thanks for your response and it is working fine.
Thanks again,
Christy
Copy link to clipboard
Copied
... cause your in overset from the start. try to give some bounds, so that at least the first words fit
var myInsertionPoint = app.activeDocument.stories[0].insertionPoints[-1];
var myAnchoredFrame = myInsertionPoint.textFrames.add(undefined, undefined, undefined,{geometricBounds: [0,0,50,50]});
myAnchoredFrame.contents = "This is an anchored frame.";
myAnchoredFrame.fit(FitOptions.FRAME_TO_CONTENT);
Edit: You'll still have to check for overflows after fitting and in case expand bounds and fit again. It's bit of buggy also in the GUI.
Hope this'll help
Hans-Gerd Claßen
Copy link to clipboard
Copied
Hi Hans,
If I add the bounds its throwing some error like
"Invalid Object for this request".
Here the portion of code I have updated:
var myFound = myDoc.findGrep (true);
try
{
for (i = 0; i < myFound.length; i++)
{
var myInsertionPoint = myFound.insertionPoints[-1];
var myAnchoredFrame = myInsertionPoint.textFrames.add(undefined, undefined, undefined,{geometricBounds: [0,0,50,50]});
Please advice.
Thanks,
Christy
Copy link to clipboard
Copied
Hi,
your changing the story by adding a textFrame, so your reference myFound is actually not valid after the first loop.
So, loop backwards when changing / deleting something: while(i--) ... or for (i < myFound.length, i >= 0; i--)
Another reason could be that a reference itsself is in overset when accessed.
Hope this'll help
Copy link to clipboard
Copied
Dear Hans,
Thanks for your response and it is working fine.
Thanks again,
Christy