2 Replies Latest reply on Aug 17, 2010 1:28 AM by magic3000_chris

    selection sequence?

    magic3000_chris Level 1

      Hi....

       

      Currently I am creating a function to combine the text from selected text frame. However, the result does not follow the sequence of my selection. For example, I select A -> C -> B or B -> C -> A, but the result only give me A -> B -> C. Is there anything that I missed in my code??

       

       

       

      if (app.documents.length != 0) {
          for (var myCounter = 0; myCounter < app.documents.length; myCounter++) {
              var myDocument = app.documents[myCounter];
              myExportPages(myDocument);
          }
      } else {
          alert("Please open a document and try again.");
      }

       

      function myExportPages(myDocument) {

       

          var myRootXMLElement = myDocument.xmlElements.item(0);
          var articleCount = myDocument.xmlElements.item(0).xmlElements.count();
          if (articleCount > 0) {
              var strText = "";
              var myXMLElement_article = myDocument.xmlElements.item(0).xmlElements.item(articleCount - 1);
              for (var j = 0; j < app.selection.length; j++) {
                  if (app.selection[j].constructor.name == "TextFrame") {
                      strText = strText + app.selection[j].texts[0].contents + "\n";
                  }
              }

             
              if (strText != "") {
                  var myXMLElement_aText = myXMLElement_article.xmlElements.add("aText", "");
                  myXMLElement_aText.xmlAttributes.add("seq", myXMLElement_article.xmlElements.count().toString());
                  var aText_Header = myXMLElement_aText.xmlAttributes.add("header", "");
                  var aText_ContentText = myXMLElement_aText.xmlAttributes.add("contentText", strText);
              } else {
                  alert("No Text Frame is selected!");
                  return;
              }
          } else {
              alert("Article is required");
              return;
          }
      }