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.
(function() {
var doc = app.activeDocument ;
for(var i = 0; i < doc.textFrames.length; i++) {
var txtFrame = doc.textFrames[i] ;
var textRange = txtFrame.s
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:
Copy link to clipboard
Copied
(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 ;
}
}
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
Copy link to clipboard
Copied
It was possible to specify this correctly until Illustrator CS3. I would consider it a bug too.
Copy link to clipboard
Copied
You did a great job to discover the problem. Thanks! I am surprised I hadn't noticed it before.
Copy link to clipboard
Copied
Thanks a lot @sttk3
Its working fine for me.
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
Copy link to clipboard
Copied
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.