13 Replies Latest reply on Jun 11, 2014 10:40 PM by hasvi

    Script for collect the 'Master page-Text frame-Content' details

    hasvi Level 1

      Hi,

       

      How to collect 'Masterpage--TextFrame--content' details from Indesign file.

      If the Master page spread has text frame, I need to collect that text frame content in the separate file. If this possible by Indesign script?

       

      thanks,

      hasvi

        • 1. Re: Script for collect the 'Master page-Text frame-Content' details
          Chinnadk Level 4

          Hi Hasvi,

           

          Try this,

           

          var doc = app.activeDocument;

          var master = doc.masterSpreads;

          var contents = "";

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

          {

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

                  {

                          contents += master[i].textFrames[j].contents + "\r";

                      }

              }

          var file = new File("c:/1.txt");

          file.open("w");

          file.write(contents);

          file.close();

           

          Regards,

          Chinna

          • 2. Re: Script for collect the 'Master page-Text frame-Content' details
            hasvi Level 1

            Hi Chinna,

             

            Very Nice, But Master page name is missing in txt file, its default to search which master page has which content.

            How can we update this?

             

            thanks

            hasvi

            • 3. Re: Script for collect the 'Master page-Text frame-Content' details
              Chinnadk Level 4

              Hi Hasvi,

               

              Here is the modified code.

               

              var doc = app.activeDocument;

              var master = doc.masterSpreads;

              var contents = "";

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

              {

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

                      {

                              contents += master[i].textFrames[j].contents + "\t" + master[i].name + "\r";

                          }

                  }

              var file = new File("c:/1.txt");

              file.open("w");

              file.write(contents);

              file.close();

               

              Regards,

              Chinna

              • 4. Re: Script for collect the 'Master page-Text frame-Content' details
                hasvi Level 1

                Hi Chinna,

                 

                Thanks a lot again for your wonderful work.

                 

                 

                by

                hasvi

                • 5. Re: Script for collect the 'Master page-Text frame-Content' details
                  hasvi Level 1

                  Hi Chinna,

                   

                  Everything is fine, but I need the text frame content from inside of Trim size, but its collect the text frame content overall masterspread. can you please correct it?

                   

                  by

                  hasvi

                  • 6. Re: Script for collect the 'Master page-Text frame-Content' details
                    hasvi Level 1

                    Hi Chinna,

                     

                    Everything is fine, but I need the text frame content from inside of Page size, but its collect the text frame content overall masterspread. can you please correct it?

                     

                    by

                    hasvi

                    • 7. Re: Script for collect the 'Master page-Text frame-Content' details
                      hasvi Level 1

                      Hi Chinna,

                       

                      Everything is fine, but I need the 'text frame content' from inside of Page size, but its collect the text frame content overall masterspread (that means out side of page). can you please correct it?

                       

                      by

                      hasvi

                      • 8. Re: Script for collect the 'Master page-Text frame-Content' details
                        Chinnadk Level 4

                        Hi Hasvi,

                         

                        Hope this helps you!

                         

                        var doc = app.activeDocument;

                        var master = doc.masterSpreads;

                        var contents = "";

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

                        {

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

                                {

                                        if(master[i].textFrames[j].parentPage != null){

                                            contents += master[i].textFrames[j].contents + "\t" + master[i].name + "\r";

                                        }

                                    }

                            }

                        var file = new File("c:/1.txt");

                        file.open("w");

                        file.write(contents);

                        file.close();

                         

                        Regards,

                        Chinna

                        • 9. Re: Script for collect the 'Master page-Text frame-Content' details
                          hasvi Level 1

                          Thanks a lot Chinna.

                           

                          by

                          hasvi

                          • 10. Re: Script for collect the 'Master page-Text frame-Content' details
                            hasvi Level 1

                            Hi Chinna,

                             

                             

                            Here my script is working properly, But I got the error message 'object is invalid' when I run the "Generic Style Log Report", at the same time my Indesign also Not Respondent (But Generic Style Log Report created in my desktop). pls correct my script.

                             

                            var w = new Window ("dialog", "Template Checklist", undefined, {closeButton: false});

                            w.alignChildren = "left";

                            var check1  = w.add ("checkbox", undefined, "Preference Settings");

                            var check2  = w.add ("checkbox", undefined, "Generic Style Log Report");

                            var check3  = w.add ("checkbox", undefined, "Keep Options Setting");

                             

                            var buttons = w.add ("group");

                            buttons.add ("button", undefined, "Ok");

                            var Exit = 0;

                            var cancel = buttons.add ("button", undefined, "Cancel")

                                    cancel.onClick = function()

                                    {

                                            w.close();

                                            Exit = 1;

                                        }

                            w.show ();

                            if(Exit ==1)

                            {

                                    this.exit();

                                }

                             

                             

                            var myDocument = app.activeDocument;

                            if (check1.value == true)

                            {

                               //this is for default preference setting for discribed preference

                             

                             

                            //this is 'Advanced Type' default setting

                            myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.inches;

                            myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.inches;

                            myDocument.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;

                            myDocument.textPreferences.superscriptPosition=33;

                                }

                             

                             

                            if (check2.value == true)

                            {

                                var myFile = File.openDialog("Choose csv file");  

                                if (!myFile){  

                                exit();  

                                }       

                                  

                                var myArray = []   

                                myFile.open('r');  

                                while (myFile.eof==false){  

                                    var line=myFile.readln().split(",");  

                                    myArray.push(line[0]);  

                                    }  

                                  

                                var myDocument = app.activeDocument;  

                                var myPstyles = app.activeDocument.allParagraphStyles;  

                                  

                                Array.prototype.contains = function(obj) {  

                                    var i = this.length;  

                                    while (i--) {  

                                        if (this[i] === obj) {  

                                            return true;  

                                        }  

                                    }  

                                    return false;  

                                }  

                                  

                                var myMissingParaStyle =[];  

                                for(var i=2; i<myPstyles.length; i++){  

                                    var myS =myPstyles[i].name;  

                                    if(myArray.contains(myS) !=true){  

                                        myMissingParaStyle.push("\n" + myS);  

                                        }  

                                    }  

                               

                                var myCstyles = app.activeDocument.allCharacterStyles;  

                                  

                                Array.prototype.contains = function(obj) {  

                                    var i = this.length;  

                                    while (i--) {  

                                        if (this[i] === obj) {  

                                            return true;  

                                        }  

                                    }  

                                    return false;  

                                }  

                                  

                                var myMissingCharStyle =[];  

                                for(var i=1; i<myCstyles.length; i++){  

                                    var myC =myCstyles[i].name;  

                                    if(myArray.contains(myC) !=true){  

                                        myMissingCharStyle.push("\n" + myC);  

                                        }  

                                    }      

                               

                                //I showed only missing styles names, If you want a report file, please you have generate it.  

                                var w=app.activeDocument;

                                var myTextFile = new File("~/Desktop/Generic Style Log Report.csv")

                                myTextFile.open("w")

                                myTextFile.write("\nParagraph Style:")

                                myTextFile.write(myMissingParaStyle)

                                myTextFile.write("\n\nCharacter Style:")

                                myTextFile.write(myMissingCharStyle)

                                myTextFile.close();

                            }

                             

                             

                            if (check3.value == true)

                            {

                                 var myPara=app.activeDocument.paragraphStyles;

                             

                             

                                for(var i=1;i<myPara.length;i++)

                                {

                                  

                                myPara[i].keepWithPrevious=false;

                                myPara[i].keepWithPrevious=false;

                                myPara[i].keepWithNext=0;

                                myPara[i].keepLinesTogether=true;

                                myPara[i].keepAllLinesTogether=false;

                                myPara[i].keepFirstLines=2;

                                myPara[i].keepLastLines=2;

                                myPara[i].startParagraph=StartParagraph.ANYWHERE;

                                }

                            }

                             

                             

                             

                             

                            var ProgressBar = function(/*str*/title)

                            {

                                 var w = new Window('palette', ' '+title, {x:0, y:0, width:340, height:60}),

                                      pb = w.add('progressbar', {x:20, y:12, width:300, height:12}, 0, 100),

                                      st = w.add('statictext', {x:10, y:36, width:320, height:20}, '');

                                 st.justify = 'center';

                                 w.center();

                                 this.reset = function(msg,maxValue)

                                      {

                                      st.text = msg;

                                      pb.value = 0;

                                      pb.maxvalue = maxValue||0;

                                      pb.visible = !!maxValue;

                                      w.show();

                                      };

                                 this.hit = function() {++pb.value;};

                                 this.hide = function() {w.hide();};

                                 this.close = function() {w.close();};

                            };

                            //------------------------------------------------

                            //      SAMPLE CODE

                            //------------------------------------------------

                            function main()

                            {

                                 var pBar = new ProgressBar("Running");

                                 var i;

                               

                                 // Routine #1

                                 pBar.reset("Please wait Processing ...", 100);

                                 for( i=0 ; i < 100; ++i, pBar.hit() )

                                      {

                                      $.sleep(10);

                                      }

                                 // Routine #2

                                 pBar.close();

                                 }

                            main();

                            exit();

                              

                             

                            by

                            hasvi

                            • 11. Re: Script for collect the 'Master page-Text frame-Content' details
                              Chinnadk Level 4

                              Hi Hasvi,

                               

                              Please remove " var w=app.activeDocument;" on 93rd line. Because variable 'w' has already been declared at the beginning of the script as a 'new window'.

                               

                              Regards,

                              Chinna

                              • 12. Re: Script for collect the 'Master page-Text frame-Content' details
                                hasvi Level 1

                                Thanks chinna

                                 

                                Sent from Yahoo Mail on Android

                                • 13. Re: Script for collect the 'Master page-Text frame-Content' details
                                  hasvi Level 1

                                  Hi chinna,

                                   

                                  If my master page do not have any text in text frame, empty master page details should be delete from csv report. Pls help

                                   

                                  var master = myDocument.masterSpreads;

                                      var contents = "";

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

                                      {

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

                                              {

                                                      if(master[i].textFrames[j].parentPage != null){

                                                          contents +="\""+ master[i].name + "\",\"" + master[i].textFrames[j].contents + "\"\r";

                                                      }

                                                  else(master[i].textFrames[j].parentPage == null){

                                                          contents +="\""+ master[i].name + "\",\"" + master[i].textFrames[j].contents + "\"\r";

                                                      }

                                                  }

                                          }

                                      var file = new File(myDocument.filePath + "/Master Page Text.csv");

                                      file.open("w");

                                      file.write(contents);

                                      file.close();

                                  FYI:

                                  1.png

                                   

                                  From above highlighted details are not necessary because there is no text in Master page

                                   

                                  by

                                  hasvi