How to determine the selection size in CS2

Photoshop Script Snippets - Note: Full Scripts go in the Photoshop Scripts Forum

Moderators: Kukurykus, Tom, xbytor

Mike Hale

How to determine the selection size in CS2

Post by Mike Hale »

I thought I would put this here as posts don't last very long at the Adobe site.

This is by Larry Ligon

var bounds = new Array();
var docRef = activeDocument;
preferences.rulerUnits = Units.PIXELS;
var layerSetRef = docRef.layerSets.add();
var layerRef = layerSetRef.artLayers.add();
docRef.activeLayer = layerRef;
docRef.selection.fill( app.foregroundColor);
bounds = layerSetRef .bounds;
alert("bounds = " + bounds );

Make a selection and run this script.

Xbytor has a version that works by using paths. It can be found as part of his XToolkit at bb/viewtopic.php?t=369


How to determine the selection size in CS2

Post by Topper »

This is exactly where I'm stuck at the moment. I tried to find XBytors solution, but his package did not install correctly. I just need to know why I get a "PS Error 8800: Command GET is not available" everytime I try to access the bounds property of a selection. There is something selected and I'm just using these two lines:

Code: Select allvar bounds = new Array();
bounds = activeDocument.selection.bounds;

Thx in advance!

P.S: This forum has already helped me with some other issues. Keep up the good work!


How to determine the selection size in CS2

Post by xbytor »

Yes, Selection.bounds is broken. Here's the code that works.

Code: Select allcTID = function(s) { return app.charIDToTypeID(s); };
Stdlib = function() {};
Stdlib.hist = function(dir) {
  function _ftn() {
    var desc = new ActionDescriptor();
    var ref = new ActionReference();
    ref.putEnumerated(cTID("HstS"), cTID("Ordn"), cTID(dir));
    desc.putReference(cTID("null"), ref);
    executeAction(cTID("slct"), desc, DialogModes.NO);


Stdlib.undo = function () {

Stdlib.redo = function () {
  Stdlib.hist("Nxt ");

Stdlib.hasSelection = function(doc) {
  var mode = app.displayDialogs;
  var res = false;
  try {
    app.displayDialogs = DialogModes.NO;
    res = true;
  } catch (e) {
  } finally {
    app.displayDialogs = mode;

  return res;

And please follow up with me in the XToolkit thread and we will see if we can get your installation issue worked out.