The itemWhose() Collection Functions

This script demonstrates how to add a itemWhose() function to any collection class.

Usage

#include "itemWhose.jsx" a1 = app.activeDocument.pageItems; a2 = a1.itemWhose( function() { return this.label=="my label" } ); function isMyLabel() { return this.label=="my label" } a3 = a1.itemWhose(isMyLabel);

The Script

// DESCRIPTION: Install itemWhose() functions. // Copyright ©2006-2009 Dirk Becker, http://www.ixta.de // This software is provided "as is", with absolutely no warranty. // Permission to install and use the software is hereby granted without fee. // The PageItems etc. objects are only accessible after first use. var doc = app.activeDocument; doc.spreads; doc.pages; doc.pageItems; Spreads.prototype.itemWhose = Pages.prototype.itemWhose = PageItems.prototype.itemWhose = function (f) { var result = []; for( var i=0; i<this.length; i++ ) if( f.apply(this.item(i)) ) result.push(this.item(i)); return result; }