Skip to main content
Known Participant
June 24, 2016
Question

Set Kerning

  • June 24, 2016
  • 4 replies
  • 1081 views

I am trying to set the kerning between chars in Illustrator. Here's my script:

var countDigits=refGrp.textFrames[0].textRange.characters.length;

for(i=0; i < countDigits; i++) {

  refGrp.textFrames[0].textRange.characters.characterAttributes.kerning=50;

  }

But it doesn't work. refGrp is defined earlier.

Any ideas?

This topic has been closed for replies.

4 replies

Dr TyrellAuthor
Known Participant
June 25, 2016

ok, but if I want to do it char by char?

Dr TyrellAuthor
Known Participant
June 25, 2016

just to add, I have now managed to set the baselineShift and TRACKING char by char, but not the kerning, so I can now control the spacing betwen chars in someway. Maybe this is by design that kerning cannot be done char by char, although it would make more sense the other way round, set tracking on whole string then set kerning char by char.

pixxxelschubser
Community Expert
Community Expert
June 25, 2016

That makes more sense for me.

I think: do not play with a fix value for the kerning!

But it is always the same procedere:

function test()

{

  var doc = app.activeDocument;

  //doc.textFrames[0].textRange.characterAttributes.kerningMethod = AutoKernType.NOAUTOKERN;

  //doc.textFrames[0].characters[1].kerning=50;

  doc.textFrames[0].characters[1].tracking=400;

  doc.textFrames[0].characters[1].baselineShift=3;

}

test ();

Define what you want to change and ready. In this case (the //kerning) and the tracking and the baselineShift of the second character of the first text frame.

Have fun

Silly-V
Legend
June 25, 2016

Oh that's where I hunted it down!

Dr TyrellAuthor
Known Participant
June 25, 2016

I tried this...

function test()

{

  var doc = app.activeDocument;

  doc.textFrames[0].textRange.characterAttributes.kerningMethod = AutoKernType.NOAUTOKERN;

  var countDigits=doc.textFrames[0].textRange.characters.length;

  for(i=0; i < countDigits; i++)

  {

  doc.textFrames[0].textRange.characters.characterAttributes.kerning=50;

  doc.textFrames[0].textRange.characters.characterAttributes.baselineShift=1;

  }

}

does nothing to the kerning, but the baselineShift works. Am I doing something wrong?

pixxxelschubser
Community Expert
Community Expert
June 25, 2016

More like this

function test()

{

  var doc = app.activeDocument;

  doc.textFrames[0].textRange.characterAttributes.kerningMethod = AutoKernType.NOAUTOKERN;

  doc.textFrames[0].textRange.kerning=50;

  doc.textFrames[0].textRange.baselineShift=1;

}

test ();

pixxxelschubser
Community Expert
Community Expert
June 24, 2016
Silly-V
Legend
June 24, 2016

You must set the kerningMethod to be on not AutoKernType.NOAUTOKERN for the textRange in order to be able to edit the value.

Sometime ago I spent hours hunting this down, and now it is my gift to you.