3

I want to write a script to reset Vertical/Horizontal Scale of a Smart Object. I tried using ArtLayer and many properties of it, but it's not success.

Example: W:100% - H:75%

app.activeDocument.activeLayer.resize(200,200);

=> W:200% - H:150%

app.activeDocument.activeLayer.resize(100,100);

=> Nothing happened. ItW:200% - H:150%

Is there anyway to get Vertical/Horizontal Scale of a SO and set it to 100% (original scale)?

Thanks

  • I've been tinkering and trying to program something that will work but it seems that smart objects can't be sized. They seem to be ignored and only rasterized layers are altered. I'm using the activeLayer.resize after altering the units to PERCENT – Ovaryraptor Feb 12 '18 at 18:29
0

Here is "working" code:

#target photoshop
try {
  var doc = app.activeDocument;

  var layers = doc.artLayers;

  var size = dialog();

  var defaultRulerUnits = app.preferences.rulerUnits;
  app.preferences.rulerUnits = Units.PERCENT;


  for (var i = 0; i < doc.artLayers.length -1; i++) {

    var activeLayer = doc.artLayers.getByName(doc.artLayers[i].name);

    var orUnits = app.preferences.rulerUnits;

    app.preferences.rulerUnits = Units.PERCENT;

    activeLayer.resize(size, size, AnchorPosition.MIDDLECENTER);

    app.preferences.rulerUnits = orUnits;

  }


} catch (e) {
  // alert( e );
}


function dialog() {

  // Dialog box...
  var myWindow = new Window("dialog", "Resize Each Layer");

  // Keeps things inline
  myWindow.orientation = "row";

  // Informational text
  myWindow.add("statictext", undefined, "New size ( percentage ):");

  // This is the box where the size is inserted
  var myText = myWindow.add("edittext", undefined, "");
  myText.characters = 5;
  myText.active = true;

  // Ok....
  myWindow.add("button", undefined, "OK");
  if (myWindow.show() == 1) return myText.text;

} 

This is an imperfect solution based on how events must be ordered.

In order to use the script currently:

  1. Open a new psd, create 3 or so different colored smart objects using the rectangle tool.
  2. Then run the script.
  3. Try entering a value like 50. This should result in each object being resized to 50% of its current size.
  4. Next try the script again (you don't have to undo anything in your psd) and try typing 150.

    This should result in objects 2.5 times their old size.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.