5 Replies Latest reply on Nov 26, 2008 4:35 PM by Len Swierski-m5Cbo1

    [JS, CS3] Need help with inserting objects into insertion point

      Hello all,

      Perhaps someone can enlighten me by providing a sample of code syntax for inserting an object into the insertion point. I am not great at scripting but I do okay and at least I have no fear. I have had success with a script that built a stacked fraction and inserted it at the insertion point by using the insertionPoint.textframes.add() method, and afterward applying an anchorYoffset to position it correctly.

      So now, I am encouraged. My new script creates a group of two objects (a textframe and an oval). I want to insert this group at the current text insertion point and apply an inline anchorYoffset to the group. However, I am stumped on exactly how to do this. The stacked fraction textframe was created by adding it to the insertion point. In this case, though, I can't make the group I created become the insertion point's contents because the contents need to be text. Obviously it is only my lack of understanding that is causing me problems.

      Can anyone help? Thanks in advance.

      Regards,

      Len Swierski
        • 1. Re: [JS, CS3] Need help with inserting objects into insertion point
          Peter Kahrel Adobe Community Professional & MVP
          You could try moving the object to the insertion point. Something like this:

          >myObject.move (LocationOptions.after, myInsertionPoint)

          Don't know if that will work, can't try it right now.

          Peter
          • 2. Re: [JS, CS3] Need help with inserting objects into insertion point
            Level 1
            I'm afraid that Peter's suggestion doesn't work. You get an error that the argument is of the wrong kind.

            The only way I know to do this is to export the group to a snippet and then place that at the insertion point. A bit clunky, but it works.

            Dave
            • 3. Re: [JS, CS3] Need help with inserting objects into insertion point
              Level 1
              Hi Len,

              You could also create the oval at the location of the insertion point, then add text to the oval. Or create a text frame inside the oval. You can also create the text frame and the oval inside another page item:

              //Given a text frame "myTextFrame"...
              
              var myInsertionPoint = myTextFrame.paragraphs.item(1).insertionPoints.item(0);
              var myInlineFrame = myInsertionPoint.rectangles.add();
              myTextFrame.parentStory.recompose();
              var myBounds = myInlineFrame.geometricBounds;
              myInlineFrame.geometricBounds = [myBounds[0], myBounds[1], myBounds[0]+72, myBounds[1]+72];
              var myOval = myInlineFrame.ovals.add({geometricBounds:myInlineFrame.geometricBounds});
              var myTextFrame = myInlineFrame.textFrames.add({geometricBounds:myInlineFrame.geometricBounds, contents:"A"});
              myTextFrame.textFramePreferences.verticalJustification = VerticalJustification.centerAlign;
              myTextFrame.paragraphs.item(0).justification = Justification.centerAlign;

              Thanks,

              Ole
              • 4. Re: [JS, CS3] Need help with inserting objects into insertion point
                Level 1
                Thanks to all who offered suggestions here. I ended up coming up with an idea just like the suggestion that Ole came up with. I added an oval and then added a textframe to the oval. There was then no need to group anything because the two objects were together from the start. The whole point was to create a bubble letter (or a letter inside a circle) for tests and multiple-choice text. When I gave the same geometric bounds for both, all worked out perfect. Thanks again.

                Len Swierski
                • 5. Re: [JS, CS3] Need help with inserting objects into insertion point
                  Harbs. Level 6
                  FYI,

                  Kris at Rorohiko recently added an incredible feature to APID (at my
                  request) ;) ...

                  There's a new opCode for moving objects inside other objects --
                  something which has been sorely missed in scripting for ever!

                  Basically you get a reference to two objects and just write:
                  app.callExtension(0x90B6C,10016,newParent,movingChild)

                  It doesn't work with insertion points, but you can add a rectangle to an
                  insertion point and move a group inside that...

                  --
                  Harbs
                  http://www.in-tools.com