Quantcast
Channel: Adobe Community : Popular Discussions - Illustrator Scripting
Viewing all articles
Browse latest Browse all 12845

Selecting every nth object in my selection

$
0
0

Hi, I am trying to create a script that selects every nth (right now its set to be 2, so every 2nd) path in my selection. Somehow this script works just a bit but very unreliable. Sometimes it creates weird patterns such as selecting first one and then not selecting the next four and selecting one more etc. The total number looks fine but the pattern is completely wrong. How can I edit so that it would select every nth path I want? My scene in illustrator is just a scene with a lot of lines(one path with only 2 anchors) copied with different colors. And I am working on illustrator cs6

 

 

Here is my code:

 

#target illustrator

var doc = app.activeDocument;

selectedObjects = doc.selection;

numSelected = 0;

for ( var i = 0; i < doc.selection.length; i++ )

{

    if ( i % 2 == 0 )

    {

        doc.selection[i].selected = true;

        numSelected++;

    } else {

  doc.selection[i].selected = false;

  }

}

alert( numSelected, "many objects Selected");


Viewing all articles
Browse latest Browse all 12845

Trending Articles