Skip to main content
Inspiring
February 23, 2012
Question

Select all objects infront of or behind and object?

  • February 23, 2012
  • 2 replies
  • 3046 views

I'd like to select an object and have a script select all objects behind that object, within that objects bounds.  I believe this is possible with z-order?  But I've never worked with Z-orders before, can someone point me in the right direction?

This topic has been closed for replies.

2 replies

Inspiring
February 23, 2012

I don't think that zorder is going to prove what you want for this… It only allows you to move forward/backward with in a layer or group container… The easy way to select objects within a set of bounds is to make a temp artboard then use that to select the art… You would need to work through the selection array and unselect whats above…? A recursive top to bottom loop could be used… Never done this mind just out my head stuff…

jsavage77Author
Inspiring
February 23, 2012

That's along the lines I was thinking.   But how am I going to test whether the object in the loop is infront of or behind the selection?

Inspiring
February 23, 2012

Give the selected page item a tag… Deselect it. Make a temporary artboard select the art use a loop through the selection deselecting until the tag is found… everything left is below? Tags are very useful to AI scripting keeping track of all sorts of info… You can put multi-tags on any art… Just an array of name & value pairs…

Larry G. Schneider
Community Expert
Community Expert
February 23, 2012

This a script from James E Talmage

/*

JET_MarqueeDeselectPartials.jsx

A Javascript for Illustrator CS2 by James E. Talmage

Purpose:

When making marquee selections in Illustrator, all objects crossed or touched by the selection marquee are selected.

Unlike most other drawing programs, Illustrator does not provide a Contact Sensitive toggle setting to cause marquee selection

to select only objects which are fully enclosed by the marquee.

This script deselects paths in the current selection which are only partially selected.

To Use:

Make a marquee or lasso selection which completely surrounds the paths desired for selection. Then run the script.

Additional paths which were only partially selected become deselected.

*/

var docRef=activeDocument;

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

    var objRef=docRef.selection;

    var unSelecteds=0;

    if(objRef.typename=="PathItem"){

        for(p=objRef.pathPoints.length-1;p>=0;p--){

            var pointRef=objRef.pathPoints

;

            if(pointRef.selected!=PathPointSelection.ANCHORPOINT){

                unSelecteds+=1;

            }

        }

    }

    if (unSelecteds>0){

        objRef.selected=false;

    }

}

alert("Partially selected paths have been deselected.");

It may serve your purpose.