3 Replies Latest reply on Mar 21, 2009 4:13 AM by (Baljeetsingh)

    Find based on style in CS2

      Hi All

      I am trying to write script for search based on paragraph style here is my code

      var myDoc = app.activeDocument;
      var myStylename = myDoc.paragraphStyles.everyItem().name;
      var myStylenamelen = myStylename.length;
      var myStyles = myDoc.paragraphStyles;
      var mySlen = myStyles.length;

      for (var a=0; myStylenamelen > a; a++) {
      for (var j=1; mySlen > j; j++)
      {
      if (myStyles[j].basedOn == myStylename[a])
      {
      alert("Paragraph style " + myStyles[j].name + " " + myStylename[a]);
      exit();
      }
      }
      }

      can anyone tell me what me doing wrong

      Thanks
      Shonky
        • 1. Re: Find based on style in CS2
          Glen_Bal Level 1
          Hi,

          Is this what you want:

          var myDoc = app.activeDocument;
          var myStyles = myDoc.paragraphStyles;
          var mySlen = myStyles.length;

          for (var a=0; mySlen > a; a++) {
          try {
          alert("Paragraph style " + myStyles[a].name + " " + myStyles[a].basedOn.name);
          } catch (e) { alert("Paragraph style " + myStyles[a].name + " undefined"); }
          }

          I don't know why you made the big construction when you can get the name of the basedOn with no extra effort. But that could be me.
          I have inserted a try-catch because you get an error when you take a basedOn of a root paragraph style.

          Greetz,
          Glen
          • 2. Re: Find based on style in CS2
            Level 1
            Dear Glen,

            Thanks for help me but i want script that alert me when i used any based on style other then [No Paragraph Style] mean i want use based on style [No Paragraph Style] in my all style if it is not then script alert me.

            I hope you help me out

            Thanks
            Shonky
            • 3. Re: Find based on style in CS2
              Level 1
              Hi Glen

              I work out on this script now

              here is what i want

              var myDoc = app.activeDocument;
              var myStylename = myDoc.paragraphStyles.everyItem().name;
              var myStyles = myDoc.paragraphStyles;
              var mySlen = myStyles.length;

              for (var j=1; mySlen > j; j++)

              {
              if (myStyles[j].basedOn != myStylename[0])
              {
              alert("Your used wrong basedon style in " + myStyles[j].name + "\r Rectify it and run script agian");
              exit();
              }
              }
              alert("Your all Paragraph style based on " + myStylename[0])

              but i really thanks for your response

              Shonky