3 Replies Latest reply on Apr 21, 2017 1:59 AM by Laurens_V

    [JS] Add section with user defined marker




      I'm trying to write (read: copy and paste bits of code from around the web) a script that adds a section to the active page with a section marker that the user defined through a prompt. This input is then sliced to also create the section prefix.

      Now I went and looked at JongWare's excellent Object Model database for the sections.add() entry, and this entry in the ExtendScript API on GitHub. But I am really confused on how to fill in the add ([reference: Page][, withProperties: Object]) to define the section as the active page with the marker and the prefix defined by the user


      Any help is appreciated


      This is what I have so far.

      var myDoc = app.activeDocument;
      var aPag = app.activeWindow.activePage.name;
      var sName = prompt("Input section name","","Section name");
      var sPre = sName.slice(0,2);
      myDoc.sections.add( xxxxxx );


      PS. This thread is closest to my question, but has not been answered and is getting quite old.

      PPS. I have the latest CC version.

        • 1. Re: [JS] Add section with user defined marker
          S Hopkins Adobe Community Professional

          Just for starters. Of course you will need to make sure the page selected does not have a section applied already, etc.

          try {

          var myDoc = app.activeDocument;

          var aPag = app.activeWindow.activePage;

          var sName = prompt ("Input section name", "", "section name");

          var mySection = myDoc.sections.add(aPag, {sectionPrefix:"B", includeSectionPrefix:true,marker:sName});

          } catch (e) {

              $.writeln("Error "+e.message+" at line "+e.line);


          • 2. Re: [JS] Add section with user defined marker
            Laurens_V Level 1

            Yes, this works perfectly (if no section is applied yet)!

            Just to understand: the add() command is filled in with

            add(startPage, {sectionProperty1: value, sectionProperty2: value})

            And the sectionProperties can be found here.

            I'm quite now to coding so I'm still trying to understand the structure.


            Thank you!

            • 3. Re: [JS] Add section with user defined marker
              Laurens_V Level 1

              A reply, since I can't seem to edit my previous post:


              I added a check to see if there is a section marker already applied:


              var myDoc = app.activeDocument;
              var aPag = app.activeWindow.activePage.documentOffset;
              var s = myDoc.pages.item(aPag).appliedSection;
              var apSec = s.marker;
              if(apSec == ""){
                var sName = prompt ("Apply a new section:", "", "section name");
                var sPre = sName.slice(0,2);
                var mySection = myDoc.sections.add(myDoc.pages.item(aPag), {sectionPrefix:sPre, includeSectionPrefix:true,marker:sName});
              } else {
                alert("Section with name " + apSec + " already applied");


              Perhaps this is useful for somebody else...