2 Replies Latest reply on Aug 17, 2010 5:27 AM by GordonEddey

    Why does the tableStyle script not work, when the other two do

    GordonEddey Level 1
      Hi, please can you help, and thank you in advance. I am stumped. As is evident I am new to scripting –  a look through all 15 pages on the forum showed me how new – and I want a workflow in which I set up styles and then use in this instance 'appliedTableStyle' to link them to the relevant table.
      My question is why does this table style script not work and appear in the palette? (when the two scripts below it for paragraphs and cells do) I have tried both doc.tableStyles.add and doc.tableStyle.add. Please show me where I am wrong, or a better alternative. Thanks.
      docTest = app.documents.add()
      table_styles(docTest)
      cell_styles(docTest)
      para_styles(docTest)
      function table_styles(doc)
      {
      with (doc)
      {
      //try {doc.tableStyles.add
      try {doc.tableStyle.add
      ({
      name: 'tableGLOBAL',
      bodyRegionCellStyle: doc.cellStyles.item( 'cellGLOBAL' ),
      headerRegionSameAsBodyRegion: true,
      bodyRowCount: 10,
      headerRowCount: 1,
      })
      }
      catch (_){}
      }
      }
      function cell_styles(doc)
      {
      with (doc)
      {
      try {doc.cellStyles.add
      ({
      name: 'cellGLOBAL',
      appliedParagraphStyle: doc.paragraphStyles.item('paraBodyGLOBAL'),
      topInset: 0,
      leftInset: 0,
      bottomInset: 0,
      rightInset: 0,
      verticalJustification: VerticalJustification.CENTER_ALIGN,
      firstBaselineOffset: FirstBaseline.LEADING_OFFSET,
        })
      }
        catch (_){}
      }
      }
      function para_styles(doc)
      {
      with (doc)
      {
      try {doc.paragraphStyles.add
      ({
        name: 'paraBodyGLOBAL',
        appliedFont: 'Arial',
        firstLineIndent: 0,
        justification: Justification.LEFT_JUSTIFIED,
        pointSize: '6pt',
        leading: '8pt'
      })
      }
      catch (_){}
      }
      }
        • 1. Re: Why does the tableStyle script not work, when the other two do
          [Jongware] Most Valuable Participant

          Your try..catch construction hides the true error -- during development of a script, you might not want to use it.

           

          When I removed it, ID only reported with the quite worthless message

           

          "Error String: This attribute is not defined for table styles

          Source: ts = doc.tableStyles.add({"

           

          without saying what attribute ... Trying them one by one, I found this peculiar result: you cannot initialize 'headerRegionSameAsBodyRegion' ... Probably because you cannot initialize it without having a header first, and you don't "have" one yet because you are still initializing the entire style.

          But this workaround works:

           

          ts = doc.tableStyles.add({
           name: 'tableGLOBAL'
           , bodyRegionCellStyle: doc.cellStyles.item( 'cellGLOBAL' )
           , headerRowCount: 1
           , bodyRowCount: 10
          });
          ts.headerRegionSameAsBodyRegion = true;
          • 2. Re: Why does the tableStyle script not work, when the other two do
            GordonEddey Level 1

            Thank you Jongware for that answer. It makes my life much happier and simpler, as has your index to InDesign scripting which I refer to all the time.

             

            Back to the script: in my own modular set up where I need defined functions to push each module to a trigger page, I could not place the ts workaround you suggested, and was given errors no matter where I placed it in relation to the curly braces. Instead I decided to redundantly define both the body and head regions independently giving them identical attributes. It's ugly, but it works. Thanks once again.

             


            function table_styles(doc)
            {
                   
                with (doc)
                            {
                    doc.tableStyles.add({
            name: 'tableGLOBAL'
            , bodyRegionCellStyle: doc.cellStyles.item( 'cellGLOBAL' )
            , headerRegionCellStyle: doc.cellStyles.item('cellGLOBAL')
            , headerRowCount: 1
            , bodyRowCount: 10
            });

                          }

             

            }

             

            //ts.headerRegionSameAsBodyRegion = true;