Copy link to clipboard
Copied
Hello!
My „mission“ this time is - shortly explained - to re-format some tables in a magazine.
For the case one chose one or more Textframes, there is a condition at the beginning of the script:
var myDoc = app.documents[0];
var myPage = myDoc.pages[0];
var allSelection = myDoc.selection;
var mySelection = allSelection[0];
var numbSelection = allSelection.length;
for (var i=0; i < numbSelection; i++) {
if (allSelection.constructor.name != "TextFrame") {
alert("Bitte wähle einen Textrahmen aus! " + allSelection + " ist KEIN Textrahmen!");
}
else if (allSelection.contents.constructor.name != "Table") {
alert("Der Textrahmen benhaltet keine Tabelle!");
}
else {alert("Die Show kann beginnen!")};
}
All I want to know now is, where is my fault (line 13.)? I want to check if there is a table inside.
else if (allSelection.tables.length > 0) {
. . .
Though this works only for frames in which a table starts. If the frame contains part of a table that continues from the previous frame you won't be able to test it like this.
P.
Copy link to clipboard
Copied
else if (allSelection.tables.length > 0) {
. . .
Though this works only for frames in which a table starts. If the frame contains part of a table that continues from the previous frame you won't be able to test it like this.
P.
Copy link to clipboard
Copied
Thank you Peter.
But, maybe in my case it has look like:
else if (allSelection.tables.length < 0) { ... ?
than it works, cool!
Copy link to clipboard
Copied
I didn't didn't see the 'k' in 'Der Textrahmen benhaltet keine Tabelle'.
The difference one single letter can make!
P.
Copy link to clipboard
Copied
If you don´t mind...
I think it must be the "1" instead the "0", like this:
else if (allSelection.tables.length < 1) { ... ?
What do you think?
Copy link to clipboard
Copied
If a frame does not contain any tables, allSelection.tables.length === 0. So if you want to test whether a frame contains any tables, you use if (allSelection.tables.length > 0).
Copy link to clipboard
Copied
I don´t know why, but when I try:
if (allSelection.tables.length > 0)...
I get allways (with each text frame selected) the result "Die Show kann beginnen!". Means, there was detected a table, even if there isn´t one.
If I try:
if (allSelection.tables.length < 1)
it works like it should.
Copy link to clipboard
Copied
If length < 1 does what you want, then that's what you should use.