2 Replies Latest reply on Sep 6, 2012 1:11 PM by philipregan

    TextType.PARAGRAPHTEXT not being honored

    philipregan

      Given the following code pulled from Adobe's own CS6 docs...

       

      // Hello Word Script
      // Remember current unit settings and then set units to 
      // the value expected by this script
      var originalUnit = app.preferences.rulerUnits;
      app.preferences.rulerUnits = Units.INCHES;
      
      
      // Create a new 2x4 inch document and assign it to a variable 
      app.documents.add( 2, 4, 72 ); // ( x, y, res )
      
      
      // Create a new art layer containing text 
      // var artLayerRef = docRef.artLayers.add();
      var artLayerRef = activeDocument.artLayers.add();
      
      artLayerRef.kind = LayerKind.TEXT;
      
      // Set the contents of the text layer. 
      var textItemRef = artLayerRef.textItem;
      
      textItemRef.contents = "A-***-bop a-loo-bop, a-***-bam-boom, Mecca lecca hi, mecca hiney ho, Unta gleeben glouten globen, Oo ee oo ah ah, ting tang walla walla bing bang, Zip-a-dee-doo-dah, zip-a-dee-ay, Supercalifragilisticexpialidocious, Da-doo ron ron, Eep opp ork ah ah, Mah na mah na, Skidamarink a dinky dink, skidamarink a doo, Whoomp! Shaka laka shaka laka shaka laka shaka, Ob-la-di, ob-la-da, Ooga chaka, ooga chaka, ooga ooga ooga chaka, Papa-oom-mow-mow, papa-oom-mow-mow";
      
      textItemRef.TextType = TextType.PARAGRAPHTEXT;
      textItemRef.width = 2; // ERROR: the requested operation is only applicable for paragraph text
      
      // Release references 
      //docRef = null;
      artLayerRef = null;
      textItemRef = null;
      
      // Restore original ruler unit setting 
      app.preferences.rulerUnits = originalUnit;
      

       

      ...setting the width of the text returns an error. The debugger shows the TextType is correct for the object. Removing the width call results in the script completing, but then the text does not wrap. Other scripts here work, but I do not understand why even when going line bby line.

       

      Also, does anyone know where to find example code on how to use the UnitValue class? It seems basic examples are missing from the docs as well.

        • 1. Re: TextType.PARAGRAPHTEXT not being honored
          Paul Riggott Level 6

          Does this help...

           

           

          // Hello Word Script
          // Remember current unit settings and then set units to 
          // the value expected by this script
          var originalUnit = app.preferences.rulerUnits;
          app.preferences.rulerUnits = Units.PIXELS;
          var black = new SolidColor(); 
          black.rgb.hexValue = '000000'; 
          // Create a new 2x4 inch document and assign it to a variable 
          app.documents.add( new UnitValue(2,'in'),new UnitValue(4,'in'), 72 ); // ( x, y, res )
          // Create a new art layer containing text 
          // var artLayerRef = docRef.artLayers.add();
          var artLayerRef = activeDocument.artLayers.add();
          artLayerRef.kind = LayerKind.TEXT;
          artLayerRef.name='test';
          // Set the contents of the text layer. 
          var textItemRef = artLayerRef.textItem;
          textItemRef.contents = "A-***-bop a-loo-bop, a-***-bam-boom, Mecca lecca hi, mecca hiney ho, Unta gleeben glouten globen, Oo ee oo ah ah, ting tang walla walla bing bang, Zip-a-dee-doo-dah, zip-a-dee-ay, Supercalifragilisticexpialidocious, Da-doo ron ron, Eep opp ork ah ah, Mah na mah na, Skidamarink a dinky dink, skidamarink a doo, Whoomp! Shaka laka shaka laka shaka laka shaka, Ob-la-di, ob-la-da, Ooga chaka, ooga chaka, ooga ooga ooga chaka, Papa-oom-mow-mow, papa-oom-mow-mow";
          textItemRef.size=10;
          textItemRef.color = black; 
          //this should be kind not TextType
          //textItemRef.TextType = TextType.PARAGRAPHTEXT;
          textItemRef.kind = TextType.PARAGRAPHTEXT; 
          textItemRef.position= Array(20, 20); 
          textItemRef.height =230;
          textItemRef.width = 110; 
          textItemRef.justification=Justification.FULLYJUSTIFIED;
          // Release references 
          //docRef = null;
          artLayerRef = null;
          textItemRef = null;
          // Restore original ruler unit setting 
          app.preferences.rulerUnits = originalUnit;
          
          
           
          • 2. Re: TextType.PARAGRAPHTEXT not being honored
            philipregan Level 1

            YES!

             

            Thank you! I figured it would be something small, but coming from years of Applescript, I am not familiar enough with JSX to pick that out.