4 Replies Latest reply on Jun 1, 2016 3:00 PM by Laubender

    Using multiple paragraph styles in one table cell

    mechaichezilla

      Hi,

       

      I'm stuck at using multiple paragraph styles inside a cell. I guess the solution is that I need to start a new paragraph, but so far I haven't found a way to do this. When I do it in InDesign directly, it works fine, but I can't start a new paragraph when using script.

       

      Here's one solution I tried:

       

      with( table){

          rows[0].cells[0].insertionPoints.item(-1).properties = {

              contents: 'String in Format 1',

              appliedParagraphStyle: styleFormat1

          };

          rows[0].cells[0].insertionPoints.item(-1).properties = {

              contents: '\rString in Format 2',

              appliedParagraphStyle: styleFormat2

          };

      }

       

      But so far I didn't manage to get a new paragraph. When you look at the IDMLs, you can see that the one from InDesign adds a new paragraph inside the cell, while the one from my code stays in the same paragraph.

       

      Here's the IDML-Result when I do it in InDesign:

       

      <Cell Self="ue0ie4i0" Name="0:0" RowSpan="1" ColumnSpan="1" AppliedCellStyle="CellStyle/$ID/[None]" AppliedCellStylePriority="0">

          <ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/Format1">

              <CharacterStyleRange AppliedCharacterStyle="CharacterStyle/$ID/[No character style]">

                  <Content>String in Format 1</Content>

                  <Br/>

              </CharacterStyleRange>

          </ParagraphStyleRange>

          <ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/Format2">

              <CharacterStyleRange AppliedCharacterStyle="CharacterStyle/$ID/[No character style]">

                  <Content>String in Format 2</Content>

              </CharacterStyleRange>

          </ParagraphStyleRange>

      </Cell>

       

      And here's the one when I'm using script:

       

      <Cell Self="ue0ie4i0" Name="0:0" RowSpan="1" ColumnSpan="1" AppliedCellStyle="CellStyle/$ID/[None]" AppliedCellStylePriority="0">

          <ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/Format2">

              <CharacterStyleRange AppliedCharacterStyle="CharacterStyle/$ID/[No character style]">

                  <Content>String in Format 1</Content>

                  <Br/>

                  <Content>String in Format 2</Content>

              </CharacterStyleRange>

          </ParagraphStyleRange>

      </Cell>

       

      So it's quite clear that my script does not add a new paragraph. Any ideas how to get a new paragraph so I can use more than one paragraph style?

        • 1. Re: Using multiple paragraph styles in one table cell
          Laubender Adobe Community Professional & MVP

          I did not test nore debug your code, but I would suggest a different method to apply contents and the two paragraph styles. Not using a with-statement.

           

          What is your version of InDesign?

           

          Example:

           

          // Add new document:
          var doc = app.documents.add();
          // Add two paragraph styles:
          var paraStyle1 = doc.paragraphStyles.add({name : "ParaStyle-1" , pointSize : 20});
          var paraStyle2 = doc.paragraphStyles.add({name : "ParaStyle-2" , pointSize : 15});
          
          // Add a new text frame (default is on page 1):
          var newTextFrame = doc.textFrames.add();
          newTextFrame.geometricBounds = [0,0,"150mm","150mm"];
          
          // Add a table to this text frame:
          var table = newTextFrame.tables.add
          (
              {
                  bodyRowCount : 4 ,
                  columnCount : 3 ,
                  width : "150mm"
              }
          
          );
          
          // Assign the contents as array:
          // The fisrt and only entry in this array will give the first cell its contents:
          table.contents =
          [
              "Paragraph 1"+"\r"+"Paragraph 2"
          ]
          
          // Assign the formatting of the two paragraphs:
          table.cells[0].paragraphs[0].appliedParagraphStyle = paraStyle1;
          table.cells[0].paragraphs[1].appliedParagraphStyle = paraStyle2;
          

           

          Result with InDesign CS6 v8.1.0 on Mac OSX 10.6.8:

           

          TwoFormattedParagraphs-Cell1.png

           

          Hope, that helps.
          Uwe

          1 person found this helpful
          • 2. Re: Using multiple paragraph styles in one table cell
            Laubender Adobe Community Professional & MVP

            As we have seen here, the properties property will not always work as expected:

            Re: How can i make this fill 50%?

             

            Also: If possible test, if the last insertion point you are using is really at the position you are assuming that it is.

            Don't know, if something like this could work inside of a with-statement for a table:

             

            $.writeln(rows[0].cells[0].insertionPoints.item(-1).index);
            

             

            Uwe

            • 3. Re: Using multiple paragraph styles in one table cell
              mechaichezilla Level 1

              Yes, that did the trick. It seems like the '\r' triggers the new paragraph once you add it directly to contents and not inside a properties object. So I just reduced my code to this and it worked just fine:

               

              with( table.rows[0].cells[0]){

                  contents = 'hello style 1\rhello style 2';

                  paragraphs[0].appliedParagraphStyle = styleFormat1;

                  paragraphs[1].appliedParagraphStyle = styleFormat2;

              }

               

              Thanks a lot!

               

              Oh, and how do format code here?

              • 4. Re: Using multiple paragraph styles in one table cell
                Laubender Adobe Community Professional & MVP

                Oh, and how do format code here?

                You have to be logged in to the forum. You would not be able to do code formatting by mail.

                And you cannot do it by answering in your Inbox. You'll need the "Use advanced editor" button at the upper right of your answering window, that will load an "insert" widget that looks like that:  >> .

                 

                Select your code text and choose "javascript" from that widget's "Syntax Highlighting" option.

                 

                UsingSyntaxHighlighting-AdvancedEditing.png

                 

                Uwe