title: Fit graphic frame to content InDesign
body: <p>I'm trying to create a script for InDesign that forces all graphic frames (rectangles) to fit to content. I am using this with XML import and some graphics–particularly in tables–come in with frames smaller than the graphic. We don't want the graphics cropped and we don't want them scaled to a smaller size, so we want to run a script that finds all graphic objects and then forces the frame to fit to the graphic. I found the following string which <em>should</em> work, but I can't get it to work for me.</p>
  <pre><code>app.activeDocument.rectangles.everyItem().fit(FitOptions.FRAME_TO_CONTENT);
  </code></pre>
  <p>I created a really simple function with this code, but it doesn't actually do anything. I'm sure I'm missing something obvious, but my JavaScript experience is pretty limited. Here's my simple function:</p>
  <pre><code>function fitToFrame(){
      app.activeDocument.rectangles.everyItem().fit(FitOptions.FRAME_TO_CONTENT);
  }
  </code></pre>
  <p>I also tried treating it like an array, but this doesn't do anything either.</p>
  <pre><code>function fitToFrame(){
      var doc=app.activeDocument;
      app.findObjectPreferences = null;
      var obj = new Array(doc.rectangles.everyItem());
      for (var i=0; i&lt;obj.length; i++){
          obj[i].fit(FitOptions.FRAME_TO_CONTENT);
      }
   }
  </code></pre>
  <p>I tried a different approach to find and identify the objects, but this still doesn't work, and I'm stuck.</p>
  <pre><code>function fitToFrame(){
      var doc=app.activeDocument;
      app.findObjectPreferences = null;
      var obj = doc.findObject();
      for (var i=0; i&lt;obj.length; i++){
          if (obj[i] instanceof Rectangle){
              obj[i].fit(FitOptions.FRAME_TO_CONTENT);
          }
      }
   }
  </code></pre>
  <p>What am I missing? I appreciate any suggestions!</p>
  <p><strong>UPDATE</strong>
  I did discover that when I run the last function listed above, <em>something</em> happens because it changes my Undo menu in the UI to &quot;Undo Set Frame Fitting Options,&quot; but nothing actually changes in the document, so I'm still stuck.</p>