/ Id-Extras Forum / How to add script for Document Actions in InDesign through FormMaker

  • Author
  • #6888 Reply
    Keltexan
    Participant

    I have a script to be added to the Document Will Save action and would like to know how to add it in InDesign through FormMaker.  I see how in the FormMaker window to add it to Document Level, but not to a Document Action. I want to save the current state of each layer (Hidden/Visible) into a hidden text field with the layer name assigned to its layer state. That way, when the document is saved and closed, it will reopen, showing the last saved layer state.  Below is a copy of a post from a forum with the example of the script I am going to try to modify to store the state of seven layers. I appreciate your help.
    ———————————————————————————————————

    Sure, let’s take a simple example. You have a layer called “Layer1” and you want to set its default state using a field.
    Create a (hidden) text field called “Layer1State” and add the following code as a doc-level script:

    var ocgArray = this.getOCGs();
    if (ocgArray!=null) {
       for (var i=0; i<ocgArray.length; i++)  {
          if (ocgArray.name=="Layer1") {
             ocgArray.state=this.getField("Layer1State").valueAsString=="1";
             break;
          }
       }
    }

    Now you just need to set the value of the field as “1” if you want the layer to be visible when the file is opened, or to anything else if you want it to be hidden.
    For example, if you want to save the current state of the layer when the file is saved, you can place this code under the document’s Will Save event:

    var ocgArray = this.getOCGs();
    if (ocgArray!=null){
       for (var i=0; i<ocgArray.length; i++){
          if (ocgArray.name=="Layer1"){
             this.getField("Layer1State").value = (ocgArray.state) ? "1" : "0";
             break;
          }
       }
    }
    • This topic was modified 1 month, 2 weeks ago by Keltexan.
    • This topic was modified 1 month, 2 weeks ago by Ariel.
    • This topic was modified 1 month, 2 weeks ago by Ariel.
    #6892 Reply
    Keltexan
    Participant
    #6912 Reply
    Ariel
    Participant

    It’s not currently possible directly to add document actions with FormMaker (you’re not the first to ask for this, so hopefully it will be added in a future update), but there is a fairly simple workaround, which is described here (with examples): https://www.id-extras.com/forums/topic/document-action-close-script/

Viewing 3 posts - 1 through 3 (of 3 total)

Tagged: 

Reply To: How to add script for Document Actions in InDesign through FormMaker
Your information: