4 Replies Latest reply on Aug 8, 2008 3:42 PM by Jim Birkenseer

    IDCS3 Mac JSX] TextFrame.parentStory returns Array of Story objects

    Jim Birkenseer Level 1
      Hi Gang,

      I'm using IDCS3 Mac.

      Has anyone had an experience where getting the parentStory from a TextFrame returns an array of Story objects instead of a single story object? I get 191 Story objects, all except the last two refer to the story for which I am looking.

      The story in the text frame is flowed across many text frames. The story consists mainly of tables that contain one row and one column. Inside the cell of each of these 1 x 1 tables is a table that has multiple rows and multiple columns. It also contains XML. This structure was created by a JSX script that I wrote.

      I tried exporting the file to INX and then reopening it, but the same thing happens. I've tried different files that I created, and all seem to suffer from the same issue.

      Below is the script I'm using for my testing.

      -- Jim

      var myDoc = app.documents.item(0);

      if (myDoc.textFrames.count() < 1)

      {

      $.writeln("No text frames found.");

      exit();

      }



      var myTextFrame = myDoc.textFrames.itemByName("LeftTF");

      if (myTextFrame == null)

      {

      $.writeln("LeftTF not found.");

      exit();

      }



      var myStories = myTextFrame.parentStory;

      if (myStories == null)

      {

      $.writeln("myStories is null.");

      exit();

      }



      if (myStories.constructor.name == "Array")

      {

      for (var k = 0; k < myStories.length; ++k)

      {

      $.writeln(k + " : " + myStories[k].id + " : " + myStories[k].constructor.name)

      }

      $.writeln("parentStory is an Array.");

      }

      else

      {

      $.writeln("parentStory is not an Array.");

      }

        • 1. Re: IDCS3 Mac JSX] TextFrame.parentStory returns Array of Story objects
          Level 1
          Are all the frames in your story labeled "LeftTF"?

          I suspect that myTextFrame is actually a multi-object specifier, so when you get the parentStory, you're actually getting the parentStory of all the text frames with that label, which happens to largely be the same story over and over.

          Dave
          • 2. Re: IDCS3 Mac JSX] TextFrame.parentStory returns Array of Story objects
            Jim Birkenseer Level 1
            Hi Dave,

            Ahh, you're spot on, as usual!!! I do have 191 text frames labeled "LeftTF", two of which are on the master pages--which explains why two of the 191 story ids are different than the others. I confirmed this behavior in a new document that I created by hand. I created four frames with the same label value and flowed a story through them all. I got the multiple story result.

            But I am still confused, and I think I need some education. When I call:

            var myTextFrame = myDoc.textFrames.itemByName("LeftTF");

            I get a single TextFrame object, not 191 of them (which I actually was concerned with when I started writing the code). Since I only got one TextFrame, I figured it returned the first one in the collection or something. So, is myTextFrame in the code above a reference to all TextFrames that have a label with the value of "LeftTF", or just a single TextFrame object?

            Also, the Object Model Browser from the ESTK Help menu states that TextFrame.parentStory returns a Story object, not an array of Story objects. Is this just a documentation issue?

            Thanks for all of your help!!!!

            -- Jim
            • 3. Re: IDCS3 Mac JSX] TextFrame.parentStory returns Array of Story objects
              Level 1
              Hi Jim,

              re: "I get a single TextFrame object, not 191 of them (which I actually was concerned with when I started writing the code). Since I only got one TextFrame, I figured it returned the first one in the collection or something. So, is myTextFrame in the code above a reference to all TextFrames that have a label with the value of "LeftTF", or just a single TextFrame object?"

              In the example above, myTextFrame appears as a single text frame object, but is, in fact, all of the text frames that have the label. (You can also use myDoc.textFrames.item("LeftTF") due to the special case label=name behavior of page items.) If you look at a value inside that text frame object (such as parentStory), you'll see arrays. (This is one of those "The Data Browser is your Friend" moments.)

              This seems peculiar, but it also seems to be the way it's been for some time. I hadn't really noticed--I was pretty sure it would return an array or a collection of text frames. The way that it's working is definitely handy (because when you're getting references to all of those objects, there's probably something you want to do to all of them), and it's probably by design.

              For now, at least, it looks to me as if the way to iterate through the text frames is to use the id property of the returned text frame object. Just get the ids listed there and use them to specify references to text frames.

              Thanks,

              Ole
              • 4. Re: IDCS3 Mac JSX] TextFrame.parentStory returns Array of Story objects
                Jim Birkenseer Level 1
                Ole,

                Ahh...I see what you mean! Thanks!

                FWIW, I did look in the data browser during my initial confusion, but I only checked the variable's type and didn't look inside its properties. Silly me, I thought that I knew what the properties would contain! ;-)

                I was sort of expecting to get an array (or collection) of TextFrame objects from the itemByName() call. I certainly wasn't expecting to get an array of Story objects from the TextFrame.parentStory call. The parentStory call happened so far down in the code from the itemByName() call (about, what, three whole lines!) that I forgot what I was doing!!! ;-)

                So, it seems like one needs to be careful when using itemByName(). This was a good learning experience for me. I'll have to try to remember this should it happen again. I love this forum because I will probably, once again, find the answer to a problem I am having where my name appears in the solution thread. 8-|

                As it turns out with most situations like this, my overall algorithm turned out to be flawed, so I'm not even using the code. Why do I enjoy coding so much?

                Thanks again!

                -- Jim