2 Replies Latest reply on Oct 5, 2016 2:12 AM by Johnwhite

    Indesign script array unfunction in parentheses

    Johnwhite Level 1

      Hi experts,

      I define the paragraph style name in a array like this:

       

       

      var 
        mDoc = app.activeDocument,
        basePara = mSelection.source.parentStory.paragraphs.previousItem(mSelection.source.paragraphs[0]),
               notesStyleNames = ["02 Note Text", "17 H1 (Note)", "18   H2 (Note)", "19     H3 (Note)"],
        tabStyles = [mDoc.tableStyles.item("Table"), mDoc.tableStyles.item("N_Table")];
      

       

       


      to tell script my selection previous para applied to style 02 Note Text", "17 H1 (Note)", "18   H2 (Note)", "19     H3 (Note), use table style "N_Table", to build the table, else use "Table" build it.

      but it unfuction,

      and I change the (Note) into _Note,like this:

       

       var 
        mDoc = app.activeDocument,
        basePara = mSelection.source.parentStory.paragraphs.previousItem(mSelection.source.paragraphs[0]),
               notesStyleNames = ["02 Note Text", "17 H1_Note", "18   H2_Note", "19     H3_Note"],
        tabStyles = [mDoc.tableStyles.item("Table"), mDoc.tableStyles.item("N_Table")];
      

       

      It works

      could some tells me why, and how to fix it?

       

      Regard
      John

        • 1. Re: Indesign script array unfunction in parentheses
          Loic.Aigon Adobe Community Professional

          Wow that's hard to understand your need.

          notesStyleNames is just an array of strings so there is absolutely no reason why it would corrupt the script execution in any way because you just modify one of the strings.

          So you may use this string later (but I can't see that inside your snippet) and that may explain the error. If you reference a style by its name, and if taht name don't match an existing style then your script will fail.

          Remember that referencing an non valid object is not raising error until you touch that object.

           

          HTH

          Loic

          http://www.ozalto.com/

          • 2. Re: Indesign script array unfunction in parentheses
            Johnwhite Level 1

            Thank you Loic,

            thank you for your response,

             

            I give a longer snippet

            so that you may be easy to understand my script:

             

            function createTable (mSelection)
            {
            mMsg.funName = "createTable()";
            var
              mDoc = app.activeDocument,
              basePara = mSelection.source.parentStory.paragraphs.previousItem(mSelection.source.paragraphs[0]),
                    notesStyleNames = ["02 Note Text", "17 H1 (Note)", "18  H2 (Note)", "19    H3 (Note)", "20      H4 (Note)", "21 IN0 (Note)", "22    IN2 (Note)", "23      IN4 (Note)", "24          IN6 (Note)", "25 P0 (Note)", "26  P2 (Note)", "27    P4 (Note)", "28      P6 (Note)", "29        P8 (Note)"],
              tabStyles = [mDoc.tableStyles.item("Table"), mDoc.tableStyles.item("N_Table")];
            if (!basePara.isValid) {
              basePara = mSelection.source.paragraphs[0];
              }
            while (!basePara.contents.match(/\S/))
              basePara = mSelection.source.parentStory.paragraphs.previousItem(basePara);
            var
              c1Indent = basePara.firstLineIndent > 0 ? basePara.firstLineIndent : 0,
              cIndent = basePara.leftIndent + c1Indent,
              mTFwidth = mSelection.container.geometricBounds[3] - mSelection.container.geometricBounds[1] - cIndent,
              cStyle = basePara.appliedParagraphStyle.name,
              tStyle = tabStyles[0];
            //  if cStyle match 'notes' change to tableStyle "N_Table"
            if (("@@" + notesStyleNames.join("@@")).search("@@" + cStyle) != -1 ) tStyle = tabStyles[1];
            //
            var
              cUserSet_1 = mDialog_1_Part (mSelection),
              cTable = mSelection.source.texts[0].convertToTable(),
              roLen = cTable.rows.length,
              coLen = cTable.columns.length,
              emptyRows = [],
              headRows = [],
              currencyRow,
              headLineRow,
              gutterRows = [],
              defaultTextStyle,
              k, mDelimiter = "!",
              cCells = cTable.rows.itemByRange(0,mEmpty.first).cells.everyItem().getElements(),
              cCell;
            
              cIndent = cUserSet_1.leftIndent == "" ? cIndent : Number(cUserSet_1.leftIndent);
              cTable.storyOffset.paragraphs[0].leftIndent = cIndent;
              cTable.appliedTableStyle = tStyle;
              cTable.cells.everyItem().appliedCellStyle = mDoc.cellStyles.item(tStyle.name);
              cTable.cells.everyItem().clearCellStyleOverrides(true);
            

             

            I define a array, and aim to let script know if my selection previous para appiled to theses style : ["02 Note Text", "17 H1 (Note)", "18   H2 (Note)", "19     H3 (Note)", "20       H4 (Note)", "21 IN0 (Note)", "22    IN2 (Note)", "23       IN4 (Note)", "24          IN6 (Note)", "25 P0 (Note)", "26   P2 (Note)", "27     P4 (Note)", "28       P6 (Note)", "29         P8 (Note)"] build a N_Table, else build  a Table

            but the script fail to recognise the parentheses which in the array.

             

            how can I fix it?

             

            thanks so much

             

            Regard

            John