Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Scripted Buttons to Run Functions

Return to Member Forum

  • Author
    Posts
    • #111198

      I apologize in advance for my extreme lack of experience. If anyone can help me a) add a button to a button collection and/or b) create the proper syntax for an event listener, I would greatly appreciate it.

      I’m trying to activate a button within my PDF to run a function in my JSX file. I’ve searched for days and all event types seem to fail when using addEventListener().

      First, I tried adding an event listener to a button named “Respond” in the Buttons and Form panel of my InDesign file:

      var myDoc = app.activeDocument;
      var submitButton = myDoc.buttons.itemByName(“Respond”); // the button in my InDesign file is named “Respond”
      submitButton.addEventListener(“onclick”, myFunction); // tried every event type I could find (mouseup, MOUSE_UP, onClick, etc)

      Note: I realized “buttons” is a collection of buttons and lacks the method “addEventListener” but every attempt to add it as a new button failed, where adding a button group actually succeeded.

      Second, I tried creating a button from scratch. The button gets created and styled, but using “buttons.add()” again. Tried various methods to add a button with “button.add()”, always getting the error “Object doesn’t support property or method ‘button'”

      var buttonGroup = myDoc.pages[myStartPage].buttons.add();
      var buttonTextFrame = myDoc.pages[myStartPage].textFrames.add();
      buttonTextFrame.contents = “Submit”;
      var buttonText = buttonTextFrame.paragraphs[0];
      buttonText.appliedFont = app.fonts.item(“DIN Next LT Pro”);
      buttonText.fontStyle = “Bold”;
      buttonText.pointSize = 11;
      buttonText.fillColor = myDoc.colors.item(“Paper”);
      buttonText.justification = Justification.centerAlign;
      buttonGroup.fillColor = myDoc.colors.item(“mhi-blue”);
      buttonGroup.geometricBounds = [“134mm”,”141mm”,”142mm”,”167mm”];
      buttonTextFrame.geometricBounds = [“136mm”,”141mm”,”142mm”,”167mm”];

    • #111213
      David Blatner
      Keymaster

      I think it’s very unlikely that you will be able to create a script in InDesign that will modify the built-in Buttons & Forms panel.

    • #111215

      Thanks for confirming that for me David. I’m admittedly geeking out as I’ve basically learned everything I know about InDesign from watching your videos on Lynda.com. Thanks again!

Viewing 2 reply threads
  • You must be logged in to reply to this topic.
Forum Ads