5 Replies Latest reply on May 7, 2008 9:18 AM by (Avi)

    [JS] Problem in Style

    Level 1
      Hello ,

      I am applying object and paragraph style to a text frame but i am getting error as Object invalid. Can anyone please check my small script. I am getting error on line number 5 as myTextFrame5 is a Invalid object

      var myTextFrame5 = myDocument.pages.item(0).textFrames.add();
      myTextFrame5.geometricBounds = ["3p4", "1p0", "36p11", "29p0"];
      var myStyle_master = app.documents[0].paragraphStyleGroups.item("NYT Byline & Text Styles").paragraphStyles.item("NYT Text");
      myTextFrame5.parentStory.paragraphs[0].appliedParagraphStyle = myStyle_master;
      var myOstyle_master = app.documents[0].objectStyles.item("2 Leg Leading Top");
      myTextFrame5.applyObjectStyle(myOstyle_master , true);
      var masterFrame = myTextFrame5.duplicate(myDocument.pages[0].appliedMaster);
      masterFrame.geometricBounds = myTextFrame5.geometricBounds;

      Please help me,

      --Avi
        • 1. Re: [JS] Problem in Style
          Level 1
          The problem is not that the text frame is invalid. It doesn't have a paragraphs[0]. That's what's invalid. Just address the first insertion point when a text frame is empty of actual text.

          Dave
          • 2. Re: [JS] Problem in Style
            Level 1
            Thank you dave,

            But know i am getting error on line number 7. The error as "Invalid value for parameter 'using' of event 'applyobjectstyle'. Expected objectstyle but received nothing"

            var myTextFrame5 = myDocument.pages.item(0).textFrames.add();
            myTextFrame5.geometricBounds = ["3p4", "1p0", "36p11", "29p0"];
            var myStyle_master = app.documents[0].paragraphStyleGroups.item("NYT Byline & Text Styles").paragraphStyles.item("NYT Text");
            myTextFrame5.parentStory.appliedParagraphStyle = myStyle_master;
            var myOstyle_master = app.documents[0].objectStyles.item("2 Leg Leading Top");
            myTextFrame5.applyObjectStyle(myOstyle_master , true); /* Getting error */
            var masterFrame = myTextFrame5.duplicate(myDocument.pages[0].appliedMaster);
            masterFrame.geometricBounds = myTextFrame5.geometricBounds;
            • 3. Re: [JS] Problem in Style
              Level 1
              Add this after the line that references the master:

              if (myOstyle_master == null) {
              alert("Check spelling of object style name");
              exit();
              }

              Dave
              • 4. Re: [JS] Problem in Style
                Level 1
                Oh -- I bet you have the object style in a stylegroup.

                Dave
                • 5. Re: [JS] Problem in Style
                  Level 1
                  I fixed this error thank you dave.
                  But the problem is still there. When you apply object style the text style and graphic style should be same as object style. In above case object style is "2 Leg Leading Top" and text and graphic style is still Basic frame. Every time i need to drag text and graphic frame to" 2 Leg Leading Top". Is there any way using script i can drag this text style and graphic style to the object style.

                  --Avi