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[i];
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.
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.constructo r.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
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[i].storyOffset.parentTextFrames[0].parentPage.parent.constr ucto 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[i].storyOffset.parentTextFrames[0].parentPage.parent.constr uctor.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.
ya, I noticed it earlier while pasting your codes in my script. But it's showing error...
If i select manually the table in master page, I run only your codes, it works fine. But If i used it on my codes, error occurs.
I think there is a error in getting the tables...
var myTables=myDocument.stories.everyItem().tables;
If I used alert(myTables[0]); it shows [Object Table]. But if I tried to select it with, app.select(myTables[0]); then it shows error, Expected selectable items, but received (Table, Table). Even i mentioned only myTables[0] Index"0".
Once again Thanks a lot for ur reply Peter....
With Regards,
Vel.
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[i].pageItems.length;
for(var j=0;j<pageitemlen;j++)
{
var v = app.activeDocument.pages[i].pageItems[j].tables;
//alert(v.length);
for(var x=0;x<v.length;x++)
{
app.select(v[x]); //here, I can select it.
app.selection[0].label = "table"+count;
count++;
myTables.push(v[i]);
}
}
}
Peter, I thank u a lot for spending ur Golden time for my issue.......
With Regards,
Vel.
Hi Peter,
Can u tell me the code to get the parent page in cs4? In cs5 the below code works fine. but throws error in cs4.
app.activeWindow.activePage = app.selection[0].parentTextFrames[0].parentPage;
Is the following is right?
app.activeWindow.activePage = app.selection[0].parentTextFrames[0].parent;
Thanks and regards,
Vel.
Google is your friend: http://forums.adobe.com/thread/615381
Dave Saunders's function there works in all versions of InDesign (from CS3 anyway).
Peter
North America
Europe, Middle East and Africa
Asia Pacific