• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Removing underline not working in Illustrator using Extendscript

Explorer ,
Oct 03, 2024 Oct 03, 2024

Copy link to clipboard

Copied

Hi Folks

The below example not woking in illustror. Initially I applied underline = true for the textrange working fine but while removing its not working. Please help on this.

var doc = app.activeDocument;
for (var i = 0; i < doc.textFrames.length; i++) {
var txtFrame = doc.textFrames[i];
var textRange = txtFrame.story.textRange;
textRange.start = 0;
textRange.length = 5;
textRange.characterAttributes.underline = false;
}
Thanks in advance
TOPICS
Bug , How-to , Scripting , Tools

Views

385

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 03, 2024 Oct 03, 2024
As for CharacterAttributes.underline, the result is caused by Illustrator's specification that it is ignored if we set the same value as the character style being applied.

The following script has a workaround function setUnderline to avoid this. Instead of just setting the underline property, try specifying it via setUnderline.
(function() {
  var doc = app.activeDocument ;
  for(var i = 0; i < doc.textFrames.length; i++) {
    var txtFrame = doc.textFrames[i] ;
    var textRange = txtFrame.s
...

Votes

Translate

Translate
Adobe
Community Expert ,
Oct 03, 2024 Oct 03, 2024

Copy link to clipboard

Copied

Hi @Jothi Sankar Anand S I think you have found a bug. I have posted a bug report. Please vote on it.

 

Here is my test script:

/**
 * @author m1b
 * @discussion https://community.adobe.com/t5/illustrator-discussions/removing-underline-not-working-in-illustrator-using-extendscript/m-p/14895226
 */
(function () {

    var doc = app.activeDocument,
        tf = doc.activeLayer.textFrames.add(),
        tr = tf.textRanges;

    tf.contents = 'ab';

    // change an attribute on the first character
    tf.textRange.characters[0].characterAttributes.baselineShift = 1;

    var results = ['Results:'];

    // test 1 on first character
    tr[0].characterAttributes.underline = true
    results.push('tr[0] underline = TRUE: '
        + (true === tr[0].characterAttributes.underline ? 'PASSED' : 'FAILED'));

    // test 2 on first character
    tr[0].characterAttributes.underline = false;
    results.push('tr[0] underline = FALSE: '
        + (false === tr[0].characterAttributes.underline ? 'PASSED' : 'FAILED'));

    // test 1 on second character
    tr[1].characterAttributes.underline = true;
    results.push('tr[1] underline = TRUE: '
        + (true === tr[1].characterAttributes.underline ? 'PASSED' : 'FAILED'));

    // test 2 on second character
    tr[1].characterAttributes.underline = false;
    results.push('tr[1] underline = FALSE: '
        + (false === tr[1].characterAttributes.underline ? 'PASSED' : 'FAILED'));

    app.redraw();
    alert(results.join('\n'));

})();

 

And my results are:

Screenshot 2024-10-03 at 18.41.01.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 03, 2024 Oct 03, 2024

Copy link to clipboard

Copied

As for CharacterAttributes.underline, the result is caused by Illustrator's specification that it is ignored if we set the same value as the character style being applied.

The following script has a workaround function setUnderline to avoid this. Instead of just setting the underline property, try specifying it via setUnderline.
(function() {
  var doc = app.activeDocument ;
  for(var i = 0; i < doc.textFrames.length; i++) {
    var txtFrame = doc.textFrames[i] ;
    var textRange = txtFrame.story.textRange ;
    textRange.start = 0 ;
    textRange.length = 5 ;
    
    setUnderline(textRange, false) ;
  }
})() ;

function setUnderline(textRange, dstUnderline) {
  var appliedCharacterStyle = textRange.characterStyles[0] ;
  var styleUnderline = appliedCharacterStyle.underline ;

  if(styleUnderline === dstUnderline) {
    appliedCharacterStyle.underline = !styleUnderline ;
    textRange.underline = dstUnderline ;
    appliedCharacterStyle.underline = styleUnderline ;
  } else {
    textRange.underline = dstUnderline ;
  }
}

Similar post:

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 03, 2024 Oct 03, 2024

Copy link to clipboard

Copied

Thanks @sttk3 that workaround is nice! I tried it with my test script and it worked. (I still consider this behaviour as a bug, by the way.)

- Mark

Screenshot 2024-10-03 at 18.51.27.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 03, 2024 Oct 03, 2024

Copy link to clipboard

Copied

It was possible to specify this correctly until Illustrator CS3. I would consider it a bug too.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 03, 2024 Oct 03, 2024

Copy link to clipboard

Copied

You did a great job to discover the problem. Thanks! I am surprised I hadn't noticed it before.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 03, 2024 Oct 03, 2024

Copy link to clipboard

Copied

Thanks a lot @sttk3 

Its working fine for me.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 23, 2024 Oct 23, 2024

Copy link to clipboard

Copied

HI @sttk3 

Superscript and Subscript working well. But while revert back to normalbaseline its not working.
Can you please advise on this below

var doc = app.activeDocument;
for (var i = 0; i < doc.textFrames.length; i++) {
var txtFrame = doc.textFrames[i];
var textRange = txtFrame.story.textRange;
textRange.start = 0;
textRange.length = 5;
// textRange.characterAttributes.baselinePosition = FontBaselineOption.SUPERSCRIPT; // this one works well
textRange.characterAttributes.baselinePosition = FontBaselineOption.NORMALBASELINE; // this one not working
}

Note: Need help on strikethrough also
Thanks in advance

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 23, 2024 Oct 23, 2024

Copy link to clipboard

Copied

LATEST

The reason it does not work is exactly the same as in the above script and the case of “Apply Character direction to textframe characters via Extendscript”.

 

Try writing your own this time.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines