4 Replies Latest reply on Apr 9, 2015 12:15 PM by raintan33

    How can I remove selected sections? [js][CC2014]

    raintan33

      Hello,

       

      I'm trying to remove selected sections from my document.

       

      I figured out how to remove them by index number like this:

       

      var myDoc = app.activeDocument;
      var mySections = myDoc.sections;
      
      mySections[1].remove();
      

       

      When I try to limit the removal of sections to just my selection, I keep getting errors. I've tried:

       

      var myDoc = app.activeDocument;
      var mySections = myDoc.sections;
      var mySelection = myDoc.selection;
      
      mySelection.sections[1].remove();
      

       

      And:

      var myDoc = app.activeDocument;
      var mySections = myDoc.sections;
      var mySelection = myDoc.selection;
      
      mySelection[0].sections[1].remove();
      

       

       

      But I keep getting Error 21 undefined is not an object on line 5.

       

      Any help is much appreciated.

        • 1. Re: How can I remove selected sections? [js][CC2014]
          cchimi Level 2

          Are you trying to remove just the selected content that falls within a particular selection? Or are you trying to select multiple sections and only remove from within them? I'm not sure I understand your objective.

           

          As for the code, sections only appear to be available as a child of the document, not of text or any other object within it. So, depending on what you're selecting, that's likely the cause of the error.

          • 2. Re: How can I remove selected sections? [js][CC2014]
            raintan33 Level 1

            I'm trying to remove the section not the content. It would be the equivalent of selecting the first page of a section in the page panel, then right-clicking on it and clicking on "Numbering and sections..." and then unchecking the "Start Section" checkbox.

             

            That's what the first code snippet does. But I was only able to do it by index number.

             

            I've read in other posts that it's difficult to specify selections in the page panel using scripting. I'm not sure if it's even possible.

            • 3. Re: How can I remove selected sections? [js][CC2014]
              cchimi Level 2

              Aha, now I understand. Yes, to my knowledge it is very difficult/impossible to interact with the pages panel selection. If you can make the selection in the document, you can use the appliedSection property of page to get the current section, but that might not suit your needs if you're trying to work from the Pages panel.

               

              In any case, if you can work backwards from your selection to a parentPage object, you can use appliedSection to get the section.

              • 4. Re: How can I remove selected sections? [js][CC2014]
                raintan33 Level 1

                Interesting - I will give that a shot. Thanks for your help!