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

Check Textframe content

Engaged ,
Mar 24, 2017 Mar 24, 2017

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.

TOPICS
Scripting

Views

635

Translate

Translate

Report

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.

Votes

Translate

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

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.

Votes

Translate

Translate

Report

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

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!

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

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?

Votes

Translate

Translate

Report

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

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

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

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