2 Replies Latest reply on Mar 27, 2012 12:58 AM by $mm

    How to add justification correctly?

    $mm

      Hi Scripters,

       

      I am new in scripting in InDesign. In my XML Import I tried to add a justification to my different textranges.

      My Problem, I can't set 3 different justifications in 1 textframe. With the textpoint size and the color it works fine.

      If I set a justification, all textranges are left, leftJustified or right..

       

      My example how I tried to do it:

       

                  preIndex = nTF.insertionPoints[-1].index;
                  nTF.insertionPoints[-1].contents = XMLdata[i]['title'];
                  endIndex = nTF.insertionPoints[-1].index;
                 
                  // Textbereich wählen und Formatierung zuweisen
                  myRange = nTF.insertionPoints.itemByRange(preIndex,  endIndex);
                  myRange.justification = Justification.leftAlign;
                  myRange.pointSize = 12;

       

                  nTF.insertionPoints[-1].contents = "\n";
                  nTF.insertionPoints[-1].contents = "\n";

       

                  preIndex = nTF.insertionPoints[-1].index;
                  nTF.insertionPoints[-1].contents = XMLdata[i]['description']; // Inhalt hinter die letzte Position des bereits vorhandenen Textframes setzen
                  endIndex = nTF.insertionPoints[-1].index;
                  //nTF.selectTextStyleRange.justification = Justification.LEFT_JUSTIFIED;
                 
                  // Textbereich wählen und Formatierung zuweisen
                  myRange = nTF.insertionPoints.itemByRange(preIndex,  endIndex);
                  myRange.justification = Justification.leftJustified;
                  myRange.pointSize = 8;

       

                 

      nTF.insertionPoints[-1].contents = "\n";

       

                              preIndex = nTF.insertionPoints[-1].index;
                              nTF.insertionPoints[-1].contents = XMLdata[x]['ean-number']; // Inhalt hinter die letzte Position des bereits vorhandenen Textframes setzen
                              endIndex = nTF.insertionPoints[-1].index;
                              //nTF.textStyleRanges[-1].justification = Justification.RIGHT_ALIGN;
                             
                              // Textbereich wählen und Formatierung zuweisen
                              myRange = nTF.insertionPoints.itemByRange(preIndex,  endIndex);
                              myRange.justification = Justification.rightAlign;
                              myRange.pointSize = 8;

       

       

      best regards

      mischa

        • 1. Re: How to add justification correctly?
          [Jongware] Most Valuable Participant

          You can set text size and color because those are Character attributes. Justification is a Paragraph attribute -- it makes sense that tou cannot set both left and right justification in a single paragraph.

           

          I fast-read your code (which is a bit unreadable due to Jive), and at a glance seems you are using "\n" to "separate" paragraphs with. Is that correct? If so, well, don't. It inserts a soft line break instead of a paragraph return (which, you might want to know, is "\r").

          • 2. Re: How to add justification correctly?
            $mm Level 1

            Thats it! Great, thank you very much Jongware! I have to use \r to get a new paragraph :]