Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Check Textframe content

Engaged ,
Mar 24, 2017 Mar 24, 2017

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.

TOPICS
Scripting
865
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 24, 2017 Mar 24, 2017

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.

Translate
Community Expert ,
Mar 24, 2017 Mar 24, 2017

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 24, 2017 Mar 24, 2017

Thank you Peter.

But, maybe in my case it has look like:

else if (allSelection.tables.length < 0) { ... ?

than it works, cool!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 24, 2017 Mar 24, 2017

I didn't didn't see the 'k' in 'Der Textrahmen benhaltet keine Tabelle'.

The difference one single letter can make!

P.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 29, 2017 Mar 29, 2017

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 30, 2017 Mar 30, 2017

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).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 31, 2017 Mar 31, 2017

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 31, 2017 Mar 31, 2017
LATEST

If length < 1 does what you want, then that's what you should use.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines