Skip to content

Instantly share code, notes, and snippets.

@hilukasz
Created June 4, 2012 20:28
Show Gist options
  • Save hilukasz/2870670 to your computer and use it in GitHub Desktop.
Save hilukasz/2870670 to your computer and use it in GitHub Desktop.
#target illustrator
//start library
// function MyLayer() { } and function SubLayer() are constructor functions
function MyLayer(input) {
this.doc = app.activeDocument;
this.myLayerIndex = input || 0;
this.myLayerItem = this.hasLayerIndex() ? this.doc.layers[this.myLayerIndex] : false;
this.subLayers = [];
var pageItem = this.myLayerItem.pageItems;
this.myLayerItem.pageItems.each(function(pageItem) {
this.subLayers.push(new SubLayer(pageItem));
});
this.width = this.myLayerItem.width;
this.height = this.myLayerItem.height;
};
MyLayer.prototype.hasLayerIndex = function() {
return this.myLayerIndex <= this.doc.layers.length - 1;
};
function SubLayer(pageItem) {
this.pageItem = pageItem;
}
SubLayer.prototype.isIn = function(parentItem) {
var parentVB = parentItem.visibleBounds;
return this.left >= parentVB[0] &&
this.top >= parentVB[1] &&
this.right <= parentVB[2] &&
this.bottom >= parentVB[3];
};
//start script
var parentLayer = new MyLayer(0);
var parentSubLayers = parentLayer.subLayers;
var currentLayer = parentSubLayers[1];
var checkLayer = subLayersTwo.subLayers[0];
currentLayer.isIn(checkLayer);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment