• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Fit anchored frames to content

Guest
Feb 26, 2013 Feb 26, 2013

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

TOPICS
Scripting

Views

911

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Feb 27, 2013 Feb 27, 2013

Dear Hans,

Thanks for your response and it is working fine.

Thanks again,

Christy

Votes

Translate

Translate
Enthusiast ,
Feb 26, 2013 Feb 26, 2013

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 27, 2013 Feb 27, 2013

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 27, 2013 Feb 27, 2013

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 27, 2013 Feb 27, 2013

Copy link to clipboard

Copied

LATEST

Dear Hans,

Thanks for your response and it is working fine.

Thanks again,

Christy

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines