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

document.selection.length only 1000 max?

New Here ,
Sep 10, 2012 Sep 10, 2012

In adobe Illustrator CS5.1 I have a script that needs to do an action on over 1000 path objects (they are tiny squares). I noticed that my script was working very strange even though I checked over the code about 10 times to make sure it was right. In the process, I found something very interesting... even though my selection consists of over 1000 path objects (and I changed selections slightly to make sure this was the case), app.activeDocument.selection.length is always 1000 unless I go below 1000 items. Is there a limit to the number of objects that are in that array? If so, what are some solutions I might use to overcome that limitation?

Thanks!

TOPICS
Scripting
2.2K
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
Adobe
Mentor ,
Sep 10, 2012 Sep 10, 2012

Kivak_Wolf wrote:

app.activeDocument.selection.length is always 1000 unless I go below 1000 items. Is there a limit to the number of objects that are in that array?

No.

You must have something else in your code causing it to limit things or improperly coded to meet your expectations. I just did a quick test with no problems. I am however not sure if there is a ceiling within illustrator for certain limits, surely at some point even without limits strange things may begin to occur in certain cases.

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
New Here ,
Sep 10, 2012 Sep 10, 2012

Very interesting! This is my code to simply check to make sure:

alert("total: " + app.activeDocument.selection.length );

If I select <1000 it says the correct number. If I select >1000 it says "total: 1000".

Odd isn't it?

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
New Here ,
Sep 10, 2012 Sep 10, 2012

I decided to do a little more testing... apparently I AM doing something prior that is causing a problem. I have a statement I thought wouldn't affect it what-so-ever:

var selection = app.activeDocument.selection;

If I ask app.activeDocument.selection.length before the statement, it returns >1000. However, if I do this assignment and then ask  app.activeDocument.selection.length, it reads back only max of 1000. Also! The new variable, selection, only has 1000 elements in it. It does not contain all of selection.

Anyone have any ideas why on earth this is happening? The reason I need a local reference of the selected objects is that I will be selecting specific ones later before I am doing referring to them. So I can't keep asking app.activeDocument.selection because it will be changing. Any ideas on some solutions?

Thansk for your help!

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
New Here ,
Sep 10, 2012 Sep 10, 2012

Finally found a work-around in case anyone is interested. Instead of just reference copying the array, you need to push each element from selected into a new array. Concat() won't work either.

All very interesting!

Thanks for the help hopefully this will prove useful to someone else too.

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
Guru ,
Sep 10, 2012 Sep 10, 2012

You may have clobbered variables… Have you quit the app and tootkit and tried again? I just selected 4k path items without issue…

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
Valorous Hero ,
Sep 10, 2012 Sep 10, 2012

It is true!  When I put a selection of 1001 into a variable, the variable.length becomes 1000.  I guess like you said, for copying the array to a variable would cut off at max 1000 -"Too many elements"  and to really get them all you have to push?

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
New Here ,
Sep 10, 2012 Sep 10, 2012

So far that is the only way I have been able to get it to work. It's surely possible that you might be able to splice/slice from 0->len but I am not sure on that. Apart from those methods, I don't know of any.

Looks fishy to me.

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
Guru ,
Sep 10, 2012 Sep 10, 2012

What version of AI are you using and what OS… I can't make this happen here using X.6.8 and CS5. I have selections in k's and this work fine to remove…

var sel = app.activeDocument.selection;

alert( "total: " + app.activeDocument.selection.length );

alert( sel.length ); // Always same as above…

for ( i = sel.length-1; i >= 0; i-- ) {

 

          sel.remove();

 

};

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
New Here ,
Sep 10, 2012 Sep 10, 2012

I went back and tried to reproduce the problem for you Mark and found out yet more interesting information. I tried your code and everything worked fine - strange considering the problem I was having before. So I went back to the original code and tried it - the problem occured. I positioned the code the exact same way and the problem still occured!

So here is what I finally determined. Check out this code:

(sorry I don't know how to format the code, if you could tell me that would be great!)

---------

alert( "doc total: " + app.activeDocument.selection.length );

var selection = app.activeDocument.selection;

alert( "sel total: " + selection.length );

----------

The expectation is that the first and second alert will be the same. However, this is not true >1000. As it turns out, it's not the method I am using that is the problem, rather, it is the variable. "selection", as it turns out, is actually an object of some sort that I never knew about. It is a bit confusing, but I can prove it by this statement:

-------

alert("Selection: " + selection);

------

Which prints out an array of objects that is the current selection. It must be a shortcut, but I never knew about it until now. But, back to the problem at hand. The problem occurs here:

-------

var selection = app.activeDocument.selection;

-------

This, oddly enough now that I know what "selection" is, seems to work so long as the number of selected elements is <=1000.

Did anyone know about the "selection" variable before?

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
Valorous Hero ,
Sep 10, 2012 Sep 10, 2012

Cool findings!

Come to think of it, I had a similar experience using the word "path" as a variable.  I 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
Guru ,
Sep 10, 2012 Sep 10, 2012

Now I can reproduce your problem here… I never use object or property names as variables…

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 ,
Sep 10, 2012 Sep 10, 2012
LATEST

correct, other languages don't even let you use reserved names or keywords, javascript does but as described above, it is not recomended.

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