14 Replies Latest reply on Jun 23, 2009 7:58 PM by dhishok

    keep master page stories from clear style overrides...

    dhishok Level 1

      Hi everyone,

       

      I am finding the stories in the document and applying clear style overrides through javascript. When i am doing this my master page story items are also get affected. Is there any option or way to skip those master page stories?

       

      Please suggest and help me out.

       

      Thanks in advance

      Thiyagu

        • 1. Re: keep master page stories from clear style overrides...
          Harbs. Level 6
          if(stories[idx].parentTextFrames[0].parent.parent instanceof MasterSpread){
            continue;
          }

           

          Harbs

          1 person found this helpful
          • 2. Re: keep master page stories from clear style overrides...
            dhishok Level 1

            Hi Harbs,

             

            Thanks for supported to my requirement. I have tried your syntax with my existing script and it shows some error like undefined object. I am unable to resolve this. Here i am putting our existing script for your reference.

             

            //================

            var myStory = app.activeDocument.pageItems.stories.everyItem().getElements();

            for (var j = myStory.length - 1; j >= 0; j--)
                {
                    var myclr = myStory[j].clearOverrides();
                }
            }

            alert ("DONE");

             

            //====================

             

            can you please look into this and help me out.

             

            Regards

            Thiyagu

            • 3. Re: keep master page stories from clear style overrides...
              dhishok Level 1

              Hi Harbs,

               

              Can you please look into this and help me out.

               

              Thiyagu

              • 4. Re: keep master page stories from clear style overrides...
                Harbs. Level 6
                var myStory = app.activeDocument.pageItems.stories.everyItem().getElements();
                for (var j = myStory.length - 1; j >= 0; j--) 
                {
                  if(myStory[j].parentTextFrames[0].parent.parent instanceof MasterSpread)
                    {
                    continue;
                    }
                  myStory[j].clearOverrides();
                }
                alert ("DONE");
                
                • 5. Re: keep master page stories from clear style overrides...
                  Martin Fischer Level 2

                  Hi Harbs,

                   

                  why do you break the loop with continue while you could beware of it with simply negating the if-condition?

                  What is the advantage?

                   

                  Martin

                  • 6. Re: keep master page stories from clear style overrides...
                    Harbs. Level 6

                    There's no major difference.

                     

                    Using continue just keeps the code flatter and is easier to read and 

                    keep track of nesting.

                     

                    If you have a lot of conditions you can just do

                    if(x) if(y)

                    etc.

                     

                    Much easier to read than

                    if(!x){

                       if(!y){

                         if(!z){

                          etc.

                         }

                       }

                    }

                     

                    This is similar to the concept of using:

                    do{

                       if(x){break}

                       if(y)

                       DoMyStuff();

                    }while(0);

                     

                    Harbs

                    • 7. Re: keep master page stories from clear style overrides...
                      dhishok Level 1

                      Hi Harbs,

                       

                      Thanks for your continuous support. I have tried your script but it again show the same error stories undefined. So i have modified the script a little bit and tried. Now the script is running but the master page stories are also get clear overrided.

                       

                      We have applied tracking to the en spaces in the running heads as well as in the folios while doing the sample. After pouring the live chapters in to the this sample we found that there is style overrides in the paragraphs. So we tried to clear overrides in all paragraphs of the stories of the pages except master pages stories through script. But the script will clear overrides in the paragraphs of master page stories also.

                       

                      Find the modified script and the sample document below and help me out...

                       

                      var myStory = app.activeDocument.stories;
                      for (var j = myStory.length - 1; j >= 0; j--)
                      {
                          if(myStory[j].parent.parent instanceof MasterSpread)
                          {
                              continue;
                          }
                          myStory[j].clearOverrides();
                      }
                      alert ("DONE");

                      Your supports are more valuable and appreciatable...

                       

                      Thanks in advance

                      Thiyagu

                      • 8. Re: keep master page stories from clear style overrides...
                        Martin Fischer Level 2

                        Hi Thiyagu,

                         

                         

                        myStory[j].parent.parent responds the parent of the parent of a story.

                        The parent of a story is a document.

                        The parent of a document is the application.

                        So myStory[j].parent.parent responds the application and will never be an instance of Spread or MasterSpread.

                         

                        The story itself is not an item of a Spread or MasterSpread, but it's textContainers are.

                        So you will have to check whether the textContainers of a story are items of a MasterSpread instead.

                        For a story cannot flow from a textframe of a MasterSpread into a linked textFrame of a Spread (vice versa) every textContainers of a story will be items either of a Spread or of a MasterSpread. So you only have to check whether the first textContainer of a story is an item of a Spread or an item of a MasterSpread (the possible others would also be items of this or that).

                         

                         

                        So try this (in CS3/4):

                         

                        var myStory = app.activeDocument.stories;
                        for (var j = myStory.length - 1; j >= 0; j--)
                        {
                             if(myStory[j].textContainers[0].parent.parent instanceof Spread)
                                 myStory[j].clearOverrides();
                        }
                        alert ("DONE");
                        

                         

                         

                         

                        Martin

                        • 9. Re: keep master page stories from clear style overrides...
                          Harbs. Level 6

                          Woops.

                           

                          I should have paid better attention...

                           

                          Yes, for Story objects you need TextContainer for CS3 and greater, and 

                          TextFrames for CS2 and earlier...

                           

                          Harbs

                          1 person found this helpful
                          • 10. Re: keep master page stories from clear style overrides...
                            dhishok Level 1

                            Hi Martin,

                             

                            Thanks for your kind support and for the detailed information. I have tried and again the master stories are get overrided. So I have just changed the instance of Spread into MasterSpread in the script and its working very fine now. I need one more help from you. If you have any guide to identify the parent, grantparent, child elements etc... for InDesign.  Or else could you please guide me how to findout those heirarchy. It would be more helpful for me. I am having only the scripting guide with me.

                             

                            Once again i am thanking you.

                             

                            Regards

                            Thiyagu

                            • 11. Re: keep master page stories from clear style overrides...
                              dhishok Level 1

                              Hi Harbs,

                               

                              Thanks for your support. What you say is exactly right. I need to learn more regarding these things.

                               

                              I am very happy to say this. That adobe building a good relationship between the people who are all in the adobe circle.

                               

                              Regards

                              Thiyagu

                              • 12. Re: keep master page stories from clear style overrides...
                                Martin Fischer Level 2

                                Hi Thiyagu,

                                 

                                you are asking for the structure of the DOM (document object model).

                                There are several charts of the hierarchical structure of the DOM, e.g. in tree view.

                                You may search for them with Google.

                                 

                                To find out, who's the parent of an object, you can check the name of the constructor of it's parent:

                                 

                                myObject.parent.constructor.name

                                 

                                You can also climb up the parents within a loop.

                                To catch the constructor of a selected object and it's parents, grandparents ... up to the 'primal father' APPLICATION in a loop you may try this short and simple code:

                                 

                                var myData = new Array;
                                if (app.selection.length > 0)
                                {
                                     var myObject = app.selection[0];
                                     myData.push(myObject.constructor.name);
                                     do
                                     {
                                          myObject = myObject.parent;
                                          myData.push(myObject.constructor.name)
                                     } while (myObject.constructor.name != 'Application')
                                     alert('Genealogy\r' + myData.join('\r'));
                                }
                                

                                 

                                But there are also parents like parentTextFrame or parentStory.

                                This special parents your would not find out with the simple code above.

                                 

                                To read more about this basic things about the structure of the document object model (and other basics) I want to recommend Peter Kahrel's Scripting InDesign CS3/4 with JavaScript to you.

                                 

                                Martin

                                • 13. Re: keep master page stories from clear style overrides...
                                  dhishok Level 1

                                  Hi Martin,

                                   

                                  Thanks for your valuable suggestion & information. I will check and let you know my doubts. Once again thank you martin.


                                  Regards

                                  Thiyagu

                                  • 14. Re: keep master page stories from clear style overrides...
                                    dhishok Level 1

                                    Hi Martin,

                                     

                                    I checked your code and it displays the parent of selected objects. Its very nice. I am much eager to learn javascript concepts more and more.

                                     

                                    Thanks martin

                                     

                                    Thiyagu