14 Replies Latest reply: Feb 8, 2013 12:28 PM by Evgeny_Trefilov RSS

    Trouble assigning TextFrame to Justification.Left

    aareiner Community Member

      Hello,

      I need some help trouble shooting a script.

      I am trying to flip the justification for all of a selected set of text frames. However, while most types of flipping work properly, the following does not

       

      if(sel[i].story.textRange.justification == Justification.RIGHT){
               sel[i].story.textRange.justification = Justification.LEFT;
      }
      
      

       

      I would expect the justification for items that are Justification.RIGHT to switch to Justification.LEFT, but they remain as Justification.RIGHT

      It does not fail, it just does not work as expected.

       

      What is odd is that it seems to work correctly for the three other types of justification I am flipping in the same script. See below for the full script.

       

      Any ideas what is causing this?

       

      try
      {
                // Check current document for textFrames.
                if ( app.documents.length < 1 ) {
                          alert ( "open a document with text objects and select them." );
                }
                else {
                          docRef = app.activeDocument;
                          if ( docRef.textFrames.length < 1 ) {
                                    alert ( "Select some text objects." );
                          }
                          //where text fames are selected swap the jusification
                          else { 
                                    sel = docRef.selection;
                                    var sellen = sel.length;
                                    for (var i=0;i<sellen ;i++)
                                    {
                                              if(sel[i].typename == "TextFrame"){
                                                        if(sel[i].story.textRange.justification == Justification.LEFT){
                                                                  sel[i].story.textRange.justification = Justification.RIGHT;
                                                        }
                                                        else if(sel[i].story.textRange.justification == Justification.RIGHT){
                                                                  sel[i].story.textRange.justification = Justification.LEFT;
                                                        }
                                                        else if(sel[i].story.textRange.justification == Justification.FULLJUSTIFYLASTLINELEFT){
                                                                  sel[i].story.textRange.justification = Justification.FULLJUSTIFYLASTLINERIGHT;
                                                        }
                                                        else if(sel[i].story.textRange.justification == Justification.FULLJUSTIFYLASTLINERIGHT){
                                                                  sel[i].story.textRange.justification = Justification.FULLJUSTIFYLASTLINELEFT;
                                                        }
                                              }
                                    }
                          }
                }
                 
                 
        
      }
      catch (e){
                alert("Script Failed!\n"+e);
      }
      
      
      
        • 1. Re: Trouble assigning TextFrame to Justification.Left
          John Hawkinson CommunityMVP

          Well, have you tried printing out sel[i].story.textRange.justification before the if to make sure that it's the way you think it is? Use $.writeln().

          Does it work if you just run one line by hand and set the justification?

          • 2. Re: Trouble assigning TextFrame to Justification.Left
            aareiner Community Member

            Hi john,

            thanks for responding.

            Yes, I have tried printing out the justification to double check the settings.

             

            I also just tried running the one line by hand. Works for switching a left justified text to Justification.RIGHT but not for switching a right justified text to Justification.LEFT

             

            app.activeDocument.selection[0].story.textRange.justification = Justification.RIGHT;

            Works on known left or center justified text

            app.activeDocument.selection[0].story.textRange.justification = Justification.LEFT;

            Fails on known right or center justified text

             

            Possible bug in the implementation?

            • 3. Re: Trouble assigning TextFrame to Justification.Left
              Muppet Mark Community Member

              I get the same results as you?

              • 5. Re: Trouble assigning TextFrame to Justification.Left
                Evgeny_Trefilov Community Member

                I have experimented a bit this this and found out that once you resize the frame, it's possible to change justification from right to left. So right after creating the frame

                myTextFrame.resize(100.01,100.01)

                should help

                • 6. Re: Trouble assigning TextFrame to Justification.Left
                  pixxxel schubser Community Member

                  Give redraw a chance:

                   

                   

                            // Check current document for textFrames.
                            if ( app.documents.length < 1 ) {
                                      alert ( "open a document with text objects and select them." );
                            }
                            else {
                                      docRef = app.activeDocument;
                                      if ( docRef.textFrames.length < 1 ) {
                                                alert ( "Select some text objects." );
                                      }
                                      //where text fames are selected swap the jusification
                                      else { 
                                                sel = docRef.selection;
                                                var sellen = sel.length;
                                                for (var i=0;i<sellen ;i++)
                                                {
                                                          if(sel[i].typename == "TextFrame"){
                                                                    if(sel[i].story.textRange.justification == Justification.LEFT){
                                                                              sel[i].story.textRange.justification = Justification.RIGHT;
                                                                    }
                                                                    else if(sel[i].story.textRange.justification == Justification.RIGHT){
                                                                              sel[i].story.textRange.justification = Justification.LEFT;
                                                                    }
                                                                    else if(sel[i].story.textRange.justification == Justification.FULLJUSTIFYLASTLINELEFT){
                                                                              sel[i].story.textRange.justification = Justification.FULLJUSTIFYLASTLINERIGHT;
                                                                    }
                                                                    else if(sel[i].story.textRange.justification == Justification.FULLJUSTIFYLASTLINERIGHT){
                                                                              sel[i].story.textRange.justification = Justification.FULLJUSTIFYLASTLINELEFT;
                                                                    }
                                                          }
                                                }
                                      }
                            }
                            redraw()
                  
                  • 7. Re: Trouble assigning TextFrame to Justification.Left
                    CarlosCanto CommunityMVP

                    this did not work on my system Win 7, CS5

                    myTextFrame.resize(100.01,100.01);
                    myTextFrame.story.textRange.justification = Justification.LEFT;
                    

                     

                     

                    this did not work either

                    sel[i].story.textRange.justification = Justification.LEFT;
                    redraw()
                    
                    • 8. Re: Trouble assigning TextFrame to Justification.Left
                      pixxxel schubser Community Member

                      Too bad, because on Windows with CS3 it works

                       

                      app.activeDocument.selection[0].story.textRange.justification = Justification.LEFT;
                      redraw()
                      

                       

                       

                      • 9. Re: Trouble assigning TextFrame to Justification.Left
                        Evgeny_Trefilov Community Member

                        I'm using

                         

                        myTextFrame.resize(100.1,100.1);

                        myTextFrame.textRange.paragraphAttributes.justification = Justification.LEFT;

                         

                         

                        100.01 turns out to be not enough! sorry for this

                         

                        redraw(); doesn't work for me neither (CS5, OS X 10.8.2)

                         

                         

                        and I don't see justification property on textRange(?) - but

                        myTextFrame.story.textRange.justification = Justification.LEFT;

                        works as well. it seems that only resizing by X axis matters actually. indeed, frame can be resized back afterwards, it just takes to 'touch' the frame.

                        • 10. Re: Trouble assigning TextFrame to Justification.Left
                          CarlosCanto CommunityMVP

                          great finding Evgeny!!! it works with

                          myTextFrame.resize(100.1,100.1);

                           

                           

                          pixxxel, I'll give it a try with CS4...it seems they broke it accidentally in that version then.

                          • 11. Re: Trouble assigning TextFrame to Justification.Left
                            pixxxel schubser Community Member

                            @CarlosCanto,

                            yes, I tried it now with CS5.1 on Win 7 and it doesn't work.

                             

                            But I found the reason for that:

                            Your paragraphstyle is the normal paragraph style, right?

                            And you can change to all justifications, but not the LEFT one?

                             

                            Make a new paragraph style with justification.FULLJUSTIFYLASTLINECENTER and apply it.

                            Now your script can change to all justifications, but not back to the FULLJUSTIFYLASTLINECENTER !

                             

                            IMHO you can change to all, but in CS5 you can't go back to the justification, which is defined in the used paragraph style.

                             

                            Is this so?

                             

                             

                            The solution should be: Use multiple paragraph styles in script

                             

                            (or Adobe wishform  --> bug or feature???)

                            • 12. Re: Trouble assigning TextFrame to Justification.Left
                              CarlosCanto CommunityMVP

                              interesting...then based on what you're saying, the safest thing to do is resize all text frames, align/justify, then resize back. I can live with that, I made an Align palette script a couple of weeks ago, I'll revise it to include these findings.

                              • 13. Re: Trouble assigning TextFrame to Justification.Left
                                CarlosCanto CommunityMVP

                                in our eyes, it is a bug...Adobe will come up saying it is a feature.

                                 

                                it seems to be easier to resize the text frames than to create paragraph styles and check each item for which one it has...

                                • 14. Re: Trouble assigning TextFrame to Justification.Left
                                  Evgeny_Trefilov Community Member

                                  I think it can be done like this:

                                  1) try to change justification

                                  2) check if it's changed

                                  3) if not, resize 100.1, then back to original, then apply justification again

                                   

                                  this is enough to do only once since the frame creation, next time justification will change fine