3 Replies Latest reply on Jan 6, 2011 4:27 PM by Dr. TYPO

    [CS4/JS] What does convertToTable return?

    [Jongware] Most Valuable Participant

      According to the ESTK Help,


      [For any text item]

      "Table convertToTable ([columnSeparator: string][, rowSeparator: string][, numberOfColumns: number=1])

      Converts the text to a table."


      but when I needed it, it seems to return a Table array instead (always of length '1', I would suspect). With that, it's quite similar to another function (which I cannot remember off the pointy top of my hat right now) -- but oughtn't this be corrected in the documentation?

        • 1. Re: [CS4/JS] What does convertToTable return?
          Dr. TYPO

          Hello Jongware,


          I'm stuck with the same problem... did you find any solution in the meantime?


          I've got this:


          //with selected text this works fine
          var MyText = app.activeDocument.selection[0].convertToTable("\t", "\r");


          alert (MyText.constructor.name);


          var MyTag = app.activeDocument.xmlElements.item(0).xmlElements.add("Table1", MyText);




          //But I would like to work like this... unfortunately this doesn't work as the constructor becomes "Array" (!?)
          var MyDoc = app.activeDocument;
          var MyBox = MyDoc.textFrames.add();
          MyBox.geometricBounds = ["0pt","0pt", "50mm", "100mm"];
          var MyTableContent = "one\ttwo\rthree\tfour";
          MyBox.contents = MyTableContent;
          var ToTable = MyBox.parentStory.characters.itemByRange(-1, -MyTableContent.length);
          var MyTable = ToTable.convertToTable();


          //so far so good, but now *ARGHH!*

          alert (MyTable.constructor.name);


          //So how can I tag the entire table?

          var MyOtherTag = app.activeDocument.xmlElements.item(0).xmlElements.add("Table1", MyTable);



          Any help/hint is appreciated :-)

          • 2. Re: [CS4/JS] What does convertToTable return?
            [Jongware]-9BC6tI Level 4

            Since the function returns an array-of-tables instead of a simple table, you work around it:


            var MyTable = ToTable.convertToTable()[0];


            -- note the [0] at the end. I can't remember if I used this at the time, but it sounds about right.


            The other function that "suddenly" returns an array was, of course, "place". It seems there is a good reason for that after all: you can select more than one document to place.

            • 3. Re: [CS4/JS] What does convertToTable return?
              Dr. TYPO Level 1

              Well... like always: muchas gracias!


              Just worx fine, thank you.