6 Replies Latest reply on Sep 10, 2012 1:21 AM by Manan Joshi

    Override master page textframes without breaking the thread

    Manan Joshi Level 4

      I have a master page with two threaded textframes. I apply this master page on a document page and want to change the text in these boxes without effecting the boxes on the master. So i try to override these textframes however overriding breaks the thread between the textframes. So what i need is the capability to change the content of the masterpage items without breaking the thread between the boxes.

       

      I have found a thread on the forum http://forums.adobe.com/message/1105153#1105153, where in Harbs mentions that we need to recreate the thread after overriding the boxes. But i made an observation, if i control shift click on one of the textframes the textframe seems to be overridden but the thread between the frames remain intact. So if its possible to do through UI there has to be a way in scripting for this.

       

      Please guide me to the correct solutions, any hints from the esteemed members of this forum is highly appreciated

       

      Thanking in advance

       

      -Manan

        • 1. Re: Override master page textframes without breaking the thread
          Marc Autret Level 4

          Hi Manan,

           

          Perhaps you can temporary group the threaded frames, apply that master group to the destination page, then ungroup.

          This way the thread is preserved.

           

          function threadOverride(/*MasterSpread*/spd, /*TextFrame*/tf, /*Page*/pg)
          {
              var t, g;
              
              try {
                  // Get the array of threaded text frames
                  // ---
                  t = tf.parentStory.textContainers;
                  
                  // Create a temporary master group --if possible!
                  // ---
                  g = spd.groups.add(t);
                  t.length = 0;
                  
                  // Apply the master group to pg --if possible!
                  // ---
                  t = g.override(pg);
                  pg = true;
          
                  // Ungroup the master group
                  // ---
                  g.ungroup();
          
                  // Store the new frames into an array
                  // ---
                  t = (g=t).pageItems.everyItem().getElements();
          
                  // Ungroup the new frames
                  // ---
                  g.ungroup();
          
                  g = null;
                  return t;
                  }
              catch(e)
                  {
                  if( !g )
                      {
                      throw "Unable to create the group from the threaded frames.";
                      }
                  if( true!==pg )
                      {
                      g.ungroup(); // restore the initial state
                      throw "Unable to send the master objects to the destination page.";
                      }
                  throw e;
                  }
          }
          
          
          // Sample code
          // ---
          var doc = app.activeDocument,
              sourceSpread = doc.masterSpreads[0],
              destPage = doc.pages[1],
              anyThreadedFrame = sourceSpread.textFrames[2];
          
          var newFrames = threadOverride(sourceSpread, anyThreadedFrame, destPage);
          if( newFrames )
              {
              try{app.select(newFrames);}
              catch(_){}
              }
          

           

          @+

          Marc

          1 person found this helpful
          • 2. Re: Override master page textframes without breaking the thread
            Manan Joshi Level 4

            Thanks Marc, i ll try this out and post my observations.

             

            However i am still curious as how to emulate achieving this same result as done by using Cntrl + ****+Click on the UI, have been trying it all morning but have not found a way to make that happen as yet.

             

            As far as i have read selecting a page item like this(cntrl + shift + click) overrides it, but if i override using my script the thread between the textframe just snaps away. So i was wondering how the folks at Adobe have implemented it, is it something out of reach of Scripting( apart from if your idea works), and only possible by the C++ sdk.

             

            Thanks

            -Manan

            • 3. Re: Override master page textframes without breaking the thread
              Marc Autret Level 4

              Hi Manan,

               

              I don't think it's possible to emulate a Cmd + Shift + Click through scripting and, as a general rule, I wouldn't recommend mimicking-UI strategies as they often lead to performance costs and tricky contextual issues.

               

              Anyway, here is how you could 'perform' such action:

               

              function threadOverrideAlt(/*MasterSpread*/spd, /*TextFrame*/tf, /*Page*/pg)
              {
                  // Active the dest page
                  // ---
                  app.activeWindow.activePage = pg;
                  
                  // Get the array of threaded text frames
                  // ---
                  var a = tf.parentStory.textContainers,
                      i = a.length;
              
                  // Make all master items disallow override
                  // ---
                  spd.pageItems.everyItem().allowOverrides = false;
                  
                  // ...except our targeted frames
                  // ---
                  while( i-- ) a[i].allowOverrides = true;
                  
                  // Invoke the menu action
                  // ---
                  app.menuActions.itemByName('$ID/Override All Master Page Items').invoke();
              
                  // Restore allowOverrides (to all master items)
                  // ---
                  spd.pageItems.everyItem().allowOverrides = true;
              }
              
              
              // Sample code
              // ---
              var doc = app.activeDocument,
                  sourceSpread = doc.masterSpreads[0],
                  destPage = doc.pages[2],
                  anyThreadedFrame = sourceSpread.textFrames[2];
              
              threadOverrideAlt(sourceSpread, anyThreadedFrame, destPage);
              

               

               

              @+

              Marc

              • 4. Re: Override master page textframes without breaking the thread
                Harbs. Level 6

                1: Interesting conclusion you came to. Not every UI feature has a corresponding scripting method. Sometimes you need to code it yourself.

                2: In your case, I'd just override the master frames as needed. You can get the master frame from the pageItem.overriddenMasterPageItem and then check the nextTextFrame to override it and link it to the local frame as needed.

                 

                HTH,

                Harbs

                • 5. Re: Override master page textframes without breaking the thread
                  Manan Joshi Level 4

                  Thanks Marc, your code got me moving in the right direction.

                   

                  -Manan

                  • 6. Re: Override master page textframes without breaking the thread
                    Manan Joshi Level 4

                    Thanks Harbs for your valuable input too..

                     

                    -Manan