title: Script to reset scale of Smart Object to 100%
body: <p>I'm trying to make a script that will take an element on a layer and restore its size to 100%.</p>
  
  <p>This is what I have so far but it doesn't seem to be working on smart objects for some reason. Am I missing something?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>try {
    var doc = app.activeDocument;
  
    var layers = doc.artLayers;
  
    var size = dialog();
    
    for (var i = 0; i &lt; 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;
  
  } </code></pre>
  </div>
  </div>
  </p>
  
  <p>It doesn't work whenever I try and run it and it does nothing to smart objects at all.</p>
  
  <p><a href="https://i.stack.imgur.com/89JJo.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/89JJo.gif" alt="enter image description here"></a></p>