Skip navigation
aareiner
Currently Being Moderated

Trouble assigning TextFrame to Justification.Left

May 24, 2012 7:46 AM

Tags: #cs5 #script #text #javascript #scripting #illustrator_cs5 #textframes

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);
}
 
 
 
Replies
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    May 24, 2012 7:56 AM   in reply to aareiner

    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?

     
    |
    Mark as:
  • Currently Being Moderated
    May 24, 2012 9:08 AM   in reply to aareiner

    I get the same results as you?

     
    |
    Mark as:
  • Currently Being Moderated
    May 24, 2012 9:28 AM   in reply to Muppet Mark

    Me too.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 8, 2013 5:19 AM   in reply to aareiner

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 8, 2013 9:13 AM   in reply to Evgeny_Trefilov

    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()
    
     
    |
    Mark as:
  • Currently Being Moderated
    Feb 8, 2013 9:50 AM   in reply to pixxxel schubser

    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()
    
     
    |
    Mark as:
  • Currently Being Moderated
    Feb 8, 2013 10:40 AM   in reply to CarlosCanto

    Too bad, because on Windows with CS3 it works

     

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

     

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 8, 2013 11:03 AM   in reply to CarlosCanto

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 8, 2013 11:41 AM   in reply to Evgeny_Trefilov

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 8, 2013 11:59 AM   in reply to CarlosCanto

    @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???)

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 8, 2013 12:05 PM   in reply to pixxxel schubser

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 8, 2013 12:05 PM   in reply to pixxxel schubser

    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...

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 8, 2013 12:28 PM   in reply to CarlosCanto

    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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points