Skip to main content
Participating Frequently
December 11, 2015
Question

Is it possible to modify textItem leading

  • December 11, 2015
  • 2 replies
  • 1023 views

Hi,

I'm trying to replace content and leading of textItems. Replacing the content goes well, but the setting the leading is proving to be impossible, the leading is completely bogus.

// this goes fine

layer.textItem.contents =layer.textItem.contents.replace(src,new_text);

// this

layer.textItem.leading =layer.textItem.size;

// results in this

BEFORE CHANGE LEADING size:46.1538505554199 px - leading:200 px

AFTER CHANGE LEADING - size:46.1538505554199 px - leading:68.7966842651367 px

I've tried both this approach and through the script listener

  var idslct = charIDToTypeID( "slct" );

      var desc7 = new ActionDescriptor();

      var idnull = charIDToTypeID( "null" );

...

[ skipping the bull ]

...

          var idPxl = charIDToTypeID( "#Pxl" );

          desc9.putUnitDouble( idLdng, idPxl, parseFloat(unit_value.value));/**/

      var idTxtS = charIDToTypeID( "TxtS" );

      desc8.putObject( idT, idTxtS, desc9 );

  executeAction( idsetd, desc8, DialogModes.NO );



Everything fails. Any ideas?

Thanks

This topic has been closed for replies.

2 replies

Chuck Uebele
Community Expert
Community Expert
December 14, 2015

Just tried 2014, and SuperMerlin's example didn't work for me, as well as the AM code that I generated in PS 2015. The code for 2014 worked for me. I put in an amount for the leading and it took that.

Chuck Uebele
Community Expert
Community Expert
December 12, 2015

I had no problem changing the leading with this. With CC 2014 and later, text size and leading as to be specified in points rather than pixels, so you need to convert the pixels to points.

var idsetd = charIDToTypeID( "setd" );

    var desc2 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref1 = new ActionReference();

        var idPrpr = charIDToTypeID( "Prpr" );

        var idTxtS = charIDToTypeID( "TxtS" );

        ref1.putProperty( idPrpr, idTxtS );

        var idTxLr = charIDToTypeID( "TxLr" );

        var idOrdn = charIDToTypeID( "Ordn" );

        var idTrgt = charIDToTypeID( "Trgt" );

        ref1.putEnumerated( idTxLr, idOrdn, idTrgt );

    desc2.putReference( idnull, ref1 );

    var idT = charIDToTypeID( "T  " );

        var desc3 = new ActionDescriptor();

        var idtextOverrideFeatureName = stringIDToTypeID( "textOverrideFeatureName" );

        desc3.putInteger( idtextOverrideFeatureName, 808465461 );

        var idtypeStyleOperationType = stringIDToTypeID( "typeStyleOperationType" );

        desc3.putInteger( idtypeStyleOperationType, 3 );

        var idautoLeading = stringIDToTypeID( "autoLeading" );

        desc3.putBoolean( idautoLeading, false );

        var idLdng = charIDToTypeID( "Ldng" );

        var idPnt = charIDToTypeID( "#Pnt" );

        desc3.putUnitDouble( idLdng, idPnt, leadingAmt );///////variable here

    var idTxtS = charIDToTypeID( "TxtS" );

    desc2.putObject( idT, idTxtS, desc3 );

executeAction( idsetd, desc2, DialogModes.NO );

Participating Frequently
December 14, 2015

Hi Chuck,

Thanks for the tip. I'm using cc2014 too. I tried replacing my code with yours (which seems to differ from mine only in variable naming and units), I get this:

Error 1220: Illegal Argument

Line: 278

->      var idT = charIDToTypeID( "T  " );


I' ve tried every single variation of the pixel-point thing in my code (pasted sample below) to no avail.


  var idsetd = charIDToTypeID( "setd" );

      var desc8 = new ActionDescriptor();

      var idnull = charIDToTypeID( "null" );

          var ref6 = new ActionReference();

          var idPrpr = charIDToTypeID( "Prpr" );

          var idTxtS = charIDToTypeID( "TxtS" );

          ref6.putProperty( idPrpr, idTxtS );

          var idTxLr = charIDToTypeID( "TxLr" );

          var idOrdn = charIDToTypeID( "Ordn" );

          var idTrgt = charIDToTypeID( "Trgt" );

          ref6.putEnumerated( idTxLr, idOrdn, idTrgt );

      desc8.putReference( idnull, ref6 );

      var idT = charIDToTypeID( "T   " );

          var desc9 = new ActionDescriptor();

          var idtextOverrideFeatureName = stringIDToTypeID( "textOverrideFeatureName" );

          desc9.putInteger( idtextOverrideFeatureName, 808465461 );

          var idtypeStyleOperationType = stringIDToTypeID( "typeStyleOperationType" );

          desc9.putInteger( idtypeStyleOperationType, 3 );

          var idautoLeading = stringIDToTypeID( "autoLeading" );

          desc9.putBoolean( idautoLeading, false );

          var idLdng = charIDToTypeID( "Ldng" );

          var idPxl = charIDToTypeID( "#Pnt" );

          desc9.putUnitDouble( idLdng, idPxl, parseFloat(unit_value.value*( 72 / 96)));/**/

      var idTxtS = charIDToTypeID( "TxtS" );

      desc8.putObject( idT, idTxtS, desc9 );

  executeAction( idsetd, desc8, DialogModes.NO );


Fiddling with the units setup in the preferences didn't make a difference.

Participating Frequently
December 21, 2015

Hi Schubser,

I'll upload a version later, it's work stuff and cannot be shared just like that. But I wanted to drop by since you mention scaling: here is the text-replacing part of the script:

                //* FOR RU,TK
                if(layer.textItem.font!="ArialNarrow-BoldItalic"){
                    layer.textItem.font="ArialNarrow-BoldItalic"
                    layer.textItem.horizontalScale=80;                                      
                    }//*/

                // main text replacement
                layer.textItem.contents =layer.textItem.contents.toLowerCase();
                layer.textItem.contents =layer.textItem.contents.replace(l_items.toLowerCase(),loc);
                ////////////////////////

/*               ///the offending part              

                layer.textItem.useAutoLeading = false; 
               

layer.textItem.leading = layer.textItem.size.value*( 72 / 96);  //setLeading(layer,layer.textItem.size) 

//


*/

I don't know if that's the kind of scaling you're referring to (removing it made no difference), but there it is.

Thanks


Hi Schubser,

In case you want to take a look at it, I uploaded a version here:
Download: Archive.zip | www.xup.in

Cheers