1 Reply Latest reply on May 26, 2010 2:42 AM by Peter Kahrel

    JS: create button contains no text field

    romanobstuder Level 1

      When working manually ins InDesign Buttons are created by taking a Text Box or an Image Box and converting it to a Button.

       

      When taking a Text Box then the resulting Button contains a Text Field for the Text "on top" of the button.

       

       

      When creating the button via script:

       

      var myButton = myPage.buttons.add({visibilityInPdf:1181247844});

       

      The button does not contain a text field.

       

      var myStates = myButton.states;

      var myStateA = myStates[0];
      var myStateB = myStates[1];
      var myStateC = myStates[2];
      $.writeln ("State A, text Frame, lenght: " + myStateA.textFrames.length);    <--- this returns 0
      I am sure there is a way to create a button with a text field...
      ... any hints anybody?
      Romano

        • 1. Re: JS: create button contains no text field
          Peter Kahrel Adobe Community Professional & MVP

          I don't have a lot of experience with buttons, but what I do remember is that you can't convert frames to buttons as you can in the UI. Instead, you create a button with the frame properties of the text frame, move the contents of the frame to the button, then delete the frame. Something like this:

           

          // select a text frame
          tf = app.selection[0];
          gb = tf.geometricBounds;
          // create a button with the same geom. bounds as the selected frame
          b = app.documents[0].buttons.add ({geometricBounds: gb});
          // create a text frame in the button
          btf = b.textFrames.add ({geometricBounds: gb});
          // move the selected frame's parent story into the frame in the button
          tf.parentStory.move (LocationOptions.after, tf.insertionPoints[0]);
          // remove the selected text frame, it's no longer needed
          tf.remove();

           

          Something like this inelegant workaround is needed because you can't move a frame into a button. So you need to create a frame in the button, them move the selected frame's content to that new frame.

           

          Peter