4 Replies Latest reply on Feb 27, 2013 3:17 AM by bacas_christy

    Fit anchored frames to content

    bacas_christy

      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[i].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

        • 1. Re: Fit anchored frames to content
          -hans- Level 4

          ... 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

          • 2. Re: Fit anchored frames to content
            bacas_christy Level 1

            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[i].insertionPoints[-1];

            var myAnchoredFrame = myInsertionPoint.textFrames.add(undefined, undefined, undefined,{geometricBounds: [0,0,50,50]});

             

            Please advice.

             

            Thanks,

            Christy

            • 3. Re: Fit anchored frames to content
              -hans- Level 4

              Hi,

               

              your changing the story by adding a textFrame, so your reference myFound[i] 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

              • 4. Re: Fit anchored frames to content
                bacas_christy Level 1

                Dear Hans,

                 

                Thanks for your response and it is working fine.

                 

                Thanks again,

                 

                Christy