Skip to main content
Inspiring
October 1, 2022
Answered

Possible to scale a selection?

  • October 1, 2022
  • 2 replies
  • 582 views

As part of a larger script I'm working on, I'm looking for a way to scale an existing selection. I have this code right now:

 

function selectionDimensions(thisSelection) {
	var selectionDimensions = [];
	var SB = activeDocument.selection.bounds;
	selectionDimensions[0] = SB[2].value - SB[0].value;
	selectionDimensions[1] = SB[3].value - SB[1].value;
	return selectionDimensions;
}

var doc_scale = 2;

app.activeDocument.pathItems.getByName('negative').makeSelection(feather, true); // Make selection from path

var n  = selectionDimensions(app.activeDocument.selection);
app.activeDocument.selection.resizeBoundary(n[0] * doc_scale, n[1] * doc_scale);

However, absolutely nothing happens to the selection when I execute it. Is the code wrong, or is it not possible to resize selections this way?

 

/Joakim

This topic has been closed for replies.
Correct answer hertze

Thanks! I figured out what I did wrong! I hadn't understood that the horisontal and vertical numbers used with resizeBoundary should be in % and not px!

2 replies

Stephen Marsh
Community Expert
Community Expert
October 1, 2022
hertzeAuthorCorrect answer
Inspiring
October 2, 2022

Thanks! I figured out what I did wrong! I hadn't understood that the horisontal and vertical numbers used with resizeBoundary should be in % and not px!

Chuck Uebele
Community Expert
Community Expert
October 2, 2022

Glad you figured it out. I can see how mixing up the unit value might make it seem like it wouldn't work. I've done things like that a bit too often.

Chuck Uebele
Community Expert
Community Expert
October 1, 2022

Have you tried using scriptListener and using the scale selection, from the menu, then inserting variables for the size?

hertzeAuthor
Inspiring
October 1, 2022

Thanks for the suggestion! I haven't! If at all possible, I'd prefer to keep with DOM scripting only, for various personal reasons... 😬

Chuck Uebele
Community Expert
Community Expert
October 1, 2022

I like DOM also, but most the time, the Action Manager code runs faster and has the ability to do more. After years of using it, I'm still trying to wrap my head around it.