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

count number of objects in a group

Engaged ,
May 03, 2017 May 03, 2017

Hi!

I don´t know if it is that obviously but I didn't found an explanation why this line causes an error:

alert(app.documents[0].groups[0].count());

The group contains a rectangle and a textFrame. (I want to separate those groups from others with more objects or other KIND of objects.)

Here I´ve read something like:

...

number count ()

Displays the number of elements in the Group.

...

Did I misunderstood the hint?

regards

A.

TOPICS
Scripting
2.3K
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 , May 03, 2017 May 03, 2017

alert(app.documents[0].groups[0].allPageItems.length)

Translate
Participant ,
May 03, 2017 May 03, 2017

Hi; try this

alert(app.documents[0].groups[0].rectangles.count());

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 ,
May 03, 2017 May 03, 2017

Hi & thanks!

herewith I just get the number of rectangles. But I need the number of all the objects inside.

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 ,
May 03, 2017 May 03, 2017

alert(app.documents[0].groups[0].allPageItems.length)

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 ,
May 03, 2017 May 03, 2017

Thank you peter for the (again) perfect shot from the hip.   

Sometimes I mess with such trifles for two days ...

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
Participant ,
May 03, 2017 May 03, 2017

Yes;
Notice the difference between the two

alert(app.documents[0].groups[0].allPageItems.length); 

1.jpg

alert(app.documents[0].groups[0].pageItems.length); 

2.jpg

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 ,
May 03, 2017 May 03, 2017

I suppose the fourth item is the group itself (?)

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
Participant ,
May 03, 2017 May 03, 2017

No! image and container(Frame)

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 ,
May 04, 2017 May 04, 2017

I try to understand...

initial situation: you have a group of a rectangel, a textFrame and a picture. Is that right?

And with "allPageImages" you can recall even "nested" objects.

That´s a good hint. thanks

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 ,
May 04, 2017 May 04, 2017

And with "allPageImages" you can recall even "nested" objects.

FWIW: One exception:
Not active states of a MultiStateObject (MSO) are left out.

Regards,
Uwe

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 ,
May 04, 2017 May 04, 2017

Hm. Seems that you removed the last reply.

FWIW: I just wanted to answer:

You first have to resolve the pageItem with getElements() ( returns an Array ).

( If you ask for pageItem you'll get pageItem ( in most cases ) 😉 )

var resolvedItem = app.documents[0].groups[0].pageItems[0].getElements()[0];

if(resolvedItem.constructor.name == "Rectangle")

{// do something};

Regards,

Uwe

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 ,
May 04, 2017 May 04, 2017
LATEST

Yes. sorry.

I found the solution and didn´t want to bother the community with boring questions...

But thanx you for your answer with helpful facts.

Regards

A.

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