Skip to main content
Velprakash
Inspiring
June 30, 2012
Answered

how to find the tables only placed on pages.

  • June 30, 2012
  • 1 reply
  • 1946 views

Hi experts,

      I'm finding all the tables in the .indd document (Non XML Indd file.) In that there are some number of tables. And a table in Master page also there. Now I'm trying to get only the tables except the master page. How can I got it?

I used the following code. But it's not working properly.

var myTables=app.activeDocument.stories.everyItem().tables;

app.select(myTables[0]);

var myTableCount=myTables.length;

alert(myTableCount);

for(var i=0;i<myTableCount;i++){

var myTableObj=myTables;

alert(myTableObj.parent);

try

{

var xxx = myTableObj.parent.parentPage.name;

if(xxx.match("^[0-9]+$"))

{

     alert("Table");

    myTableObj.label="table"+(i+1);

    }

else

{

   alert("Master-Page Table");

    }

}

catch(e)

{

    alert(e.message);

    }

}

Always throwing catch loop...

Can anyone guide me.................................!

Thanks and Regards,

Vel.

This topic has been closed for replies.
Correct answer Velprakash

There's a space in constr uctor (which I managed to put there, sorry). That's probably the problem.

Peter


Hi Peter,

        At last, I complete it by the below codes. It make me to struggle a lot.....................

var pagelen = app.activeDocument.pages.length;

alert(pagelen);

for(var i=0;i<pagelen;i++)

{

    var pageitemlen = app.activeDocument.pages.pageItems.length;

    for(var j=0;j<pageitemlen;j++)

    {

        var v = app.activeDocument.pages.pageItems.tables;

        //alert(v.length);

        for(var x=0;x<v.length;x++)

        {

            app.select(v);                                                      //here, I can select it.

            app.selection[0].label = "table"+count;

            count++;

            myTables.push(v);

            }

        }

    }

Peter, I thank u a lot for spending ur Golden time for my issue.......

With Regards,

Vel.

1 reply

Peter Kahrel
Community Expert
Community Expert
June 30, 2012

The parent of a document page is a Spread, that of a master page is a MasterSpread. Therefore:

if (myTable.storyOffset.parentTextFrames[0].parentPage.parent.constructor.name != 'MasterSpread')

     $.writeln ('Not on a master page);

else

     $.alert ('On a master page');

This is in CS5 and later. Earlier versions don't have the parentPage property, andthe parenthood of pages is a bit different in those earlier versions.

Peter

Velprakash
Inspiring
June 30, 2012

Hi Peter,

       Thank you for your reply........... I used the above codes. But It throws an error, "Undefined is not an Object" in the line, 

if (myTables.storyOffset.parentTextFrames[0].parentPage.parent.constructo r.name != 'MasterSpread')

I've table in master page also. But what I've to do is, I've to find all other tables in document pages, except Master page & assign Label...

I used the below codes.

var myTables=myDocument.stories.everyItem().tables;

var myTableCount=myTables.length;

for(var i=0;i<myTableCount;i++){

    if (myTables.storyOffset.parentTextFrames[0].parentPage.parent.constructor.name != 'MasterSpread')

    {

        alert("Master Page");

        }

var myTableObj=myTables.item(i);

myTableObj.label="table"+(i+1);

}

I'm struggling in this issue for a long time. Can u help!!!

With thanks and Regards,

Vel.

Peter Kahrel
Community Expert
Community Expert
June 30, 2012

There's a space in constr uctor (which I managed to put there, sorry). That's probably the problem.

Peter