Current Position:Home > CS3 JS flag which page has empty frame

CS3 JS flag which page has empty frame

Update:10-11Source: network consolidation
I am trying to put together a script that will detect pages that have 2 types of elements.
1. blank graphic frames
2. graphic frames with images larger than the frame holding it.
I've created a simple 5 page doc and placed images on page 1 and 3. So the frist step is can I flag that page 1 and 3 have image on them.
This is what I have so far
var myDoc = app.activeDocument;
var myPages = myDoc.pages;
var myRecs = myDoc.rectangles;
for (var j = myPages.length - 1; j >= 0; j--) {
if(myPages[j].rectangles.length >= 1){
$.writeln("page "+j+" has a frame.");
And it returns the following in the console which is correct.
page 2 has a frame.
page 0 has a frame.
Is there a way to check if the frame has an image and if it image fits the frame or not?

The Best Answer

I usually switch to spread coordinates to avoid those kinds of issues (although others swear by page coordinates). I use these two functions:
    function saveMeasures(doc, units) {
      var uPrefs = doc.viewPreferences;
      var uMeasures = {
        zp:doc.zeroPoint = {
      doc.zeroPoint = [0,0];
      return uMeasures;
    function restoreMeasures(doc, measures) { = {
      doc.zeroPoint = measures.zp;
I call these like this--notice the code is inside a function; that makes it possible to use return to exit the script which in turn makes it possible to call the restore function as I exit, using the return in two different places:
  function splitElements(aDoc) {
    var curPage = app.activeWindow.activePage;
    var prevPage = aDoc.pages[curPage.documentOffset - 1];
    if (prevPage === aDoc.pages[-1]) {
      alert("Don't run this script on the first page of a document.");
    var uMeasures = saveMeasures(aDoc, MeasurementUnits.points);
    var oSized = getOsetElement(prevPage);
    if (oSized === null) return restoreMeasures(aDoc, uMeasures); // nothing to do
    splitElement(oSized, prevPage, curPage, aDoc);
    return restoreMeasures(aDoc, uMeasures);
This script needed to convert the measurement units to points because it needs to do calculations involving leading and stroke weights, both of which are provided in points.