Skip to main content
Participant
October 14, 2025
Answered

undo() - uncaught exception (-29) error

  • October 14, 2025
  • 2 replies
  • 215 views

Hello Experts,

 

I'm using the InDesign 20.4.1.

 

Steps to reproduce the issues:

1. Create a master page containing the multiple text frames.
2. Apply the master page to the interior pages (ensure there are at least 5–10 pages).
3. Save the document, close it, and reopen it to clear the history stack.

 

Here is my script to undo the overridden textframe by the script:

 

var Doc = app.activeDocument;
for (z = 0; z < Doc.pages.length; z++) {
page = Doc.pages[z];
var count = 0;
for (j = 0, k = page.appliedMaster.textFrames.length / 2 + 1; j <= k; j++) {
if (page.appliedMaster.textFrames[j].constructor.name == "TextFrame") {
try { page.appliedMaster.textFrames[j].override(page); count++; } catch (e) { continue; }
try { Doc.undo(); } catch (e) { alert(e);}
}

}
}


If there is no undoable data, the process must be routed to catch statement and alert the error message (e).

While running the above script, the attached uncaught exception error occurred.

 

Note: I couldn't reproduce the same issue in InDesign 19.5.

 

Thanks in advance.

 

Regards,
Ashrafali R.

Correct answer Marc Autret

Hi Ashrafali R.

 

Not sure what you're trying to achieve but playing with doc.undo() is not a good idea unless you have no other option.

 

In your particular case, it seems that you need to detect, count and/or report text frames according to their ‘overridden’ state relative to the parent (=master) page. Properties like page.masterPageItems, item.overridden and possibly item.overriddenMasterPageItem should be sufficient to safely investigate.

 

Here is a messy and oversimplified example that illustrates the use of these features:

 

(function(  doc,pgs,pg,mfs,tfs,i,n,t,s)
//----------------------------------
// Demo: Simple Text Frame Report
// - assuming at most ONE parent page in the hierarchy
// - disregarding grouped/nested frames etc.
{
   doc = app.properties.activeDocument;
   if( !doc ) return;
   
   pgs = doc.pages.everyItem().getElements();
   for( ; pg=pgs.pop() ; )
   {
      // Master frames (not overridden).
      mfs = pg.masterPageItems || [];
      for
      (
         i=mfs.length ; i-- ;
         'TextFrame' != mfs[i].constructor.name
         && mfs.splice(i,1)
      );

      // Local frames (incl. overridden)
      tfs = [];
      n = (t=pg.textFrames).length;
      while( n )
      {
         t = t.everyItem();
         s = t.overridden.join('')
            .replace(/true/g,'1')
            .replace(/false/g,'0');

         if( -1 == s.indexOf('1') ) break;

         for
         (
            tfs=t.getElements(), i=n ;
            i-- ;
            '1' != s.charAt(i) && tfs.splice(i,1)
         );

         break;
      }
      
      // Summary
      s = "Page " + pg.name + "\r" +
         "Overall visible frames: " + (n+mfs.length) + "\r" +
         "----------------------\r\r" +
         "On Master: " + mfs.length + "\r\r" +
         "On Page:   " + n + "\r" +
         " - from master: " + tfs.length + "\r" +
         " - others:      " + (n-tfs.length);
      alert( s );
      
      // At this point,
      // the array `mfs` contains the master (not overridden) frames,
      // the array `tfs` contains the local frames that were overridden.
   }

})();

 

Best,

M

2 replies

Marc Autret
Marc AutretCorrect answer
Legend
October 14, 2025

Hi Ashrafali R.

 

Not sure what you're trying to achieve but playing with doc.undo() is not a good idea unless you have no other option.

 

In your particular case, it seems that you need to detect, count and/or report text frames according to their ‘overridden’ state relative to the parent (=master) page. Properties like page.masterPageItems, item.overridden and possibly item.overriddenMasterPageItem should be sufficient to safely investigate.

 

Here is a messy and oversimplified example that illustrates the use of these features:

 

(function(  doc,pgs,pg,mfs,tfs,i,n,t,s)
//----------------------------------
// Demo: Simple Text Frame Report
// - assuming at most ONE parent page in the hierarchy
// - disregarding grouped/nested frames etc.
{
   doc = app.properties.activeDocument;
   if( !doc ) return;
   
   pgs = doc.pages.everyItem().getElements();
   for( ; pg=pgs.pop() ; )
   {
      // Master frames (not overridden).
      mfs = pg.masterPageItems || [];
      for
      (
         i=mfs.length ; i-- ;
         'TextFrame' != mfs[i].constructor.name
         && mfs.splice(i,1)
      );

      // Local frames (incl. overridden)
      tfs = [];
      n = (t=pg.textFrames).length;
      while( n )
      {
         t = t.everyItem();
         s = t.overridden.join('')
            .replace(/true/g,'1')
            .replace(/false/g,'0');

         if( -1 == s.indexOf('1') ) break;

         for
         (
            tfs=t.getElements(), i=n ;
            i-- ;
            '1' != s.charAt(i) && tfs.splice(i,1)
         );

         break;
      }
      
      // Summary
      s = "Page " + pg.name + "\r" +
         "Overall visible frames: " + (n+mfs.length) + "\r" +
         "----------------------\r\r" +
         "On Master: " + mfs.length + "\r\r" +
         "On Page:   " + n + "\r" +
         " - from master: " + tfs.length + "\r" +
         " - others:      " + (n-tfs.length);
      alert( s );
      
      // At this point,
      // the array `mfs` contains the master (not overridden) frames,
      // the array `tfs` contains the local frames that were overridden.
   }

})();

 

Best,

M

Participant
October 14, 2025

Hi,

 

Thanks for your response.

 

I do try the suggested way. It override the master textframes but it does not undo its overrides. i.e. It enables all the master textframes.

 

Regards,

Ashrafali R.

leo.r
Community Expert
Community Expert
October 14, 2025
quote

Thanks for your response.


By @ashrafali_r_srm

 

that response was posted by an AI spambot. you can ignore it. the user will be eradicated soon, hopefully.