12 Replies Latest reply on Jul 9, 2014 6:21 AM by Dapeamel

    masterpages and content

    Dapeamel Level 1

      Hello guys,

       

      I need help to write a simple function that checks if there is content/no content on a master page,

       

      if there is content on the master pages ("You got content on the masterpages")

      if there is no content on the masterpages(" You have got no content on the masterpages")

       

       

      Could someone help me out,

       

      Thank you in advance

        • 1. Re: masterpages and content
          Chinnadk Level 4

          Hi,

           

          Try this.

           

          var doc = app.activeDocument,
              _masters = doc.masterSpreads;
          
          for(var i=0;i<_masters.length;i++)
          {
                  for(var j =0;j<_masters[i].pages.length;j++)
                  {
                          for(var k=0;k<_masters[i].pages[j].textFrames.length;k++)
                          {
                                  if(_masters[i].pages[j].textFrames[k].contents !="")
                                  {
                                          alert(("You got content on the masterpages"))
                                      }
                                  else
                                  {
                                          alert(" You have got no content on the masterpages")
                                      }
                              }
                      }
              }
          

           

          Regards,

          Chinna

          • 2. Re: masterpages and content
            Dapeamel Level 1

            Awesome Thank you sir,

            how do I include pictures?

            if there is picutes also?

             

            Thank you in advance sir.

            • 3. Re: masterpages and content
              Dapeamel Level 1

              if there is no content on the masterpage, the script doesn't saying anything.

              • 4. Re: masterpages and content
                Dapeamel Level 1

                this code work,

                 

                but still got problem if there is pictures.

                 

                var doc = app.activeDocument, 

                    _masters = doc.masterSpreads; 

                 

                for(var i=0;i<_masters.length;i++) 

                        for(var j =0;j<_masters[i].pages.length;j++) 

                        { 

                                for(var k=0;k<_masters[i].pages[j].textFrames.length;k++) 

                                { 

                                        if(_masters[i].pages[j].textFrames[k].contents !="") 

                                        { 

                                                alert(("You got content on the masterpages")) 

                  exit();

                                            } 

                  } 

                  } 

                 

                    } 

                 

                 

                  alert(" You have got no content on the masterpages") 

                • 5. Re: Re: masterpages and content
                  Chinnadk Level 4

                  For pictures try this.

                   

                  var doc = app.activeDocument,
                      _masters = doc.masterSpreads;
                  
                  for(var i=0;i<_masters.length;i++)
                  {
                          for(var j =0;j<_masters[i].pages.length;j++)
                          {
                                  for(var k=0;k<_masters[i].pages[j].rectangles.length;k++)
                                  {
                                          if(_masters[i].pages[j].rectangles[k].graphics.length != 0)
                                          {
                                                  alert("You got image on the masterpages") 
                                              }
                                          else
                                          {
                                                  alert(" You have got no image on the masterpages")
                                              }
                                      }
                              }
                      }
                  

                   

                  Regards,

                  Chinna

                  • 6. Re: Re: Re: masterpages and content
                    Dapeamel Level 1

                    thank you sir,

                     

                    here is the final code

                    I do wonder

                    is it possible to make this to 1 loop instead of 2 functions + 2 loops?

                     

                     

                     

                    //variables

                    var doc = app.activeDocument,

                    _masters = doc.masterSpreads;

                     

                     

                     

                    //functions

                    FindImagesOnMasterPages ()

                     

                    function FindImagesOnMasterPages()

                    {

                      for(var i=0;i<_masters.length;i++)

                      {

                      for(var j =0;j<_masters[i].pages.length;j++)

                      {

                      for(var k=0;k<_masters[i].pages[j].rectangles.length;k++)

                      {

                      if(_masters[i].pages[j].rectangles[k].graphics.length != 0)

                      {

                      alert("You got one or more images on the masterpages")

                      FindTextOnMasterPages ()

                      exit();

                        }

                        }

                      }

                      alert(" You have got no image on the masterpages")

                      }

                    }

                     

                    FindTextOnMasterPages ()

                     

                     

                     

                    function FindTextOnMasterPages ()

                    {

                      for(var i=0;i<_masters.length;i++)

                      {

                      for(var j =0;j<_masters[i].pages.length;j++)

                      {

                      for(var k=0;k<_masters[i].pages[j].textFrames.length;k++)

                      {

                      if(_masters[i].pages[j].textFrames[k].contents !="")

                      {

                      alert(("You got text on the masterpages"))

                      exit();

                      }

                      }

                      }

                      alert(" You have got no text on the masterpages")

                      }

                    }

                     

                     

                     

                     

                     

                     

                     

                     

                     

                    thank you in advance.

                    • 7. Re: Re: Re: Re: masterpages and content
                      Kai Rübsamen Adobe Community Professional

                      If I understand the question correct, I would do it in this way:

                       

                      var curDoc = app.activeDocument,
                          allMasterSpreads = curDoc.masterSpreads,
                          withContent = [];
                          noContent = [];
                          
                      for ( var i = 0; i < allMasterSpreads.length; i++ ) {
                          var curMasterSpread = allMasterSpreads[i];
                          if ( curMasterSpread.pageItems.length > 0 ) {
                              withContent.push( curMasterSpread.name );
                          }
                          else {
                              noContent.push( curMasterSpread.name );
                          }  
                      }
                      
                      alert( "Masterpages\rContent on masterpage:\r" + withContent.join("\r") + "\r\r" 
                          + "No content on masterpage:\r" + noContent.join("\r")); 
                      
                      • 8. Re: Re: Re: Re: masterpages and content
                        Dapeamel Level 1

                        Your code doesnt work at all..

                        • 9. Re: Re: Re: Re: masterpages and content
                          Kai Rübsamen Adobe Community Professional

                          What should I do with such a info?

                           

                          You asked for a script, that check if there is content on a masterpage. My lines collect all masterSpreads and check if there is any page item on it. Then give an alert, an only one alert for all master pages.

                          It work perfectly here!

                          • 10. Re: Re: Re: Re: masterpages and content
                            Dapeamel Level 1

                            strange,

                            the script you written doesn't work in adobe cs 6

                            • 11. Re: Re: Re: Re: masterpages and content
                              Kai Rübsamen Adobe Community Professional

                              Hm! Sorry to hear that. I built a example with 3 masterpages in CS5.5. Masterpage A and C with some elements. Masterpage B with nothing. If I test my lines in CS5.5 and CS6 I get the attached alert.Bildschirmfoto 2014-07-09 um 15.18.38.png

                              • 12. Re: Re: Re: Re: masterpages and content
                                Dapeamel Level 1

                                ah I C Kai thats fine, thank you for you tried anyway

                                awesome help anyway.