3 Replies Latest reply on May 20, 2011 1:44 AM by Nadia_Humphrey

    How to make a script treat only tables of one layer?

    Nadia_Humphrey

      Hi guys

       

      Could anyone  point the way to performing the below code only on one layer in  Indesign CS2?

      I also need to treat tables on "layer1" only.

       

       

      with(app.activeDocument){

      for(  storyIndex = 0; storyIndex < stories.length; storyIndex++)
               {
                  var myStory = stories.item( storyIndex );
                  
                  for (tableIndex = 0; tableIndex <  myStory.tables.length; tableIndex++)
                  {
                      //do things here
                  }
              }

      }

       

      This works on the  whole document but how can I ask Indesign to treat only tables in  "layer1". The layer object does not contain the story object, so I cant  adjust the "with" statement above.

      Basically what I need to do is untag all XMLelements within a table of layer but i have given the obove code for simplicity.

       

      Can anyone guide me on this?

       

      Thanks

       

      Nadia

        • 1. Re: How to make a script treat only tables of one layer?
          John Hawkinson Level 5

          CS2, huh? If you have not already, you should budget for an upgrade to CS5.5 (or better yet, CS5 right now and get the free CS5.5 upgrade,so you have both, assuming that offer is still outstanding).

           

          Generally using with is discouraged. It makes it hard to tell what's really going on in your program and is considered bad style [at least by me]. Better to use either a temporary variable or app.activeDocument.stories explicitly.

           

          Stories do not themselves have a concept of a layer, because they are composed of textFrames and those could be on different layers.

          But let's assume that you care about the layer of the first textFrame in each story.

           

          Then:

          var
            stories = app.activeDocument.stories,
            storyIndex, myStory,
            tableIndex;
          for (storyIndex = 0; storyIndex < stories.length; storyIndex++) {
            myStory = stories[storyIndex];
            if (myStory.textFrames[0].itemLayer.name === 'layer1') {
              for (tableIndex = 0;
                   tableIndex <  myStory.tables.length;
                   tableIndex++
              ) {
                //do things here
              }
            }
          }
          

           

          (I also use stories[15] instead of stories.item(15) and declare all vars at the top.)

          1 person found this helpful
          • 2. Re: How to make a script treat only tables of one layer?
            John Hawkinson Level 5

            Err, I suppose really you would be better off not considering the stories at all and just looping over the textframes of the layer. That would be simpler and faster, I guess I didn't read your text too closely and just focused on the code, sorry!

            But both ways work. This is all untested of course.

            1 person found this helpful
            • 3. Re: How to make a script treat only tables of one layer?
              Nadia_Humphrey Level 1

              Hi John

               

              Thanks for your reply. Your answers have helped me come up with a way to do what I had to.

              Thanks for the scripting guidance. Infact am new to scripting and used snippets found here and there so it does not always follow good practice.

              I will try the upgrade to cs5 soon

               

              Thanks again

              Nadia