5 Replies Latest reply on Dec 20, 2016 1:52 AM by Laubender

    change section marker error

    hamdifem Level 1

      I give a part marker to a page

      Then I want to give the part marker back to the same page

      I'm getting an error

      I can not change current (available) section marker

      Error: This page already has another section

       

       

      var w = new Window("dialog", "Section");
      var panel = w.add('panel', undefined, "----");
      var grup = panel.add('group', undefined, "");
      grup.orientation = "row";
      grup.add('statictext', undefined, "Page");
      var sayfa = grup.add('edittext', [0, 0, 50, 25], "1")
      grup.add('statictext', undefined, "Section Marker");
      sayfa.graphics.font = "Tahoma:16";
      var kisim_isaretcisi = grup.add('edittext', [0, 0, 50, 25], "A")
      kisim_isaretcisi.graphics.font = "Tahoma:16";
      kisim_isaretcisi.active = true;
      w.add('button', undefined, 'Tamam', {name: 'OK'}).onClick = function() {
      w.close(12345);
      }
      if(w.show() == 12345) {  
      var doc = app.activeDocument;   
      var ksm = kisim_isaretcisi.text;  
      var syf = Number(sayfa.text);  
      var addd = doc.sections.add(doc.pages.item(syf-1));
      addd.marker = ksm;
      }
      
        • 1. Re: change section marker error
          Peter Kahrel Adobe Community Professional & MVP

          The message is clear: you can apply a section to a page only once. To apply a section again, first delete the section.

          • 2. Re: change section marker error
            hamdifem Level 1

            How to express it is or not part

             

            if(part){  //part code ??

            remove

            }else{

            add

            }

            • 3. Re: change section marker error
              Peter Kahrel Adobe Community Professional & MVP

              Sorry, I don't understand what you mean.

              • 4. Re: change section marker error
                hamdifem Level 1

                How can I query does it have section starting point in a page?

                • 5. Re: change section marker error
                  Laubender Adobe Community Professional & MVP

                  Hi,

                  removing a section when found and adding a section with one single change perhaps in the value of the marker property is a bit "brute force" I think.

                   

                  Nevertheless here a script snippet, that will remove and add a section, if the page of interest is already starting with a section. Adapt it to your needs:

                   

                  /*
                      
                      Adds a section to the document beginning with the page of interest
                      Removes and adds section if a section starts with the page of interest.
                  
                      IMPORTANT NOTES: 
                      You cannot remove the section that starts on page one of every document.
                      
                      Removing and adding section is brute force, 
                      if you only want to change e.g. a marker of an existing section.
                      
                  */
                  
                  var doc = app.documents[0];
                  
                  // The third page in the document:
                  var pageOfInterest = doc.pages[2];
                  
                  // Gather all the pages where sections begin:
                  var pagesWhereSectionsStart = doc.sections.everyItem().pageStart;
                  var indexesOfPagesWithSection = [];
                  
                  // Preparing an array to hold the indexes of the sections.
                  // The array's index however denotes the index of a page.
                  
                  // indexesOfPagesWithSection[0] holds always value 0 
                  // because doc.sections[0] starts always on page 1 of a document.
                  
                  // Example:
                  // If doc.pages[123] is the start of doc.sections[1], the second section in the document,
                  // the value of indexesOfPagesWithSection[123] is 1
                  
                  
                  // pagesWhereSectionsStart contains page objects.
                  // Loop that array:
                  for(var n=0;n<pagesWhereSectionsStart.length;n++)
                  {
                      var indexOfSection = n;
                      var indexOfPageWhereSectionStarts = pagesWhereSectionsStart[n].documentOffset;
                      
                      // Feed the array:
                      indexesOfPagesWithSection[indexOfPageWhereSectionStarts] = indexOfSection;
                  };
                  
                  var indexOfPageOfInterst = pageOfInterest.documentOffset;
                  
                  if(indexOfPageOfInterst in indexesOfPagesWithSection)
                  {
                      doc.sections[  indexesOfPagesWithSection[ indexOfPageOfInterst ]  ].remove();
                  };
                  
                  var newSection = doc.sections.add(pageOfInterest);
                  

                   

                  Regards,
                  Uwe