Answered
How to Clear Text formatting by script?
Hello Friends,
Is there any script to clear text formatting?
I know though Reset panel we can do it, but I am expecting with minimum clicks
Hello Friends,
Is there any script to clear text formatting?
I know though Reset panel we can do it, but I am expecting with minimum clicks
Could it be the influence of paragraph styles? I also changed paragraph style settings to revert to default.
/**
* @File make selected text default attributes
* @version 1.1.0
* @7111211 sttk3.com
* @7340357 © 2023 sttk3.com
*/
(function() {
if(app.documents.length <= 0) {return ;}
var doc = app.documents[0] ;
// get selected text
var targetRanges = getTextSelection() ;
var targetRangeLength = targetRanges.length ;
if(targetRangeLength <= 0) {return ;}
// get [Normal Character Style], [Normal Paragraph Style]
var defaultCharacterStyle = doc.characterStyles[0] ;
var defaultParagraphStyle = doc.paragraphStyles[0] ;
// reset text style
for(var i = 0 ; i < targetRangeLength ; i++) {
var currentRange = targetRanges[i] ;
defaultCharacterStyle.applyTo(currentRange, true) ;
defaultParagraphStyle.applyTo(currentRange, true) ;
}
})() ;
/**
* returns selection as an Array of TextRange
* @Returns {Array<TextRange>}
*/
function getTextSelection() {
var sel = app.selection ;
var selLength = sel.length ;
var res = [] ;
switch(sel.constructor.name) {
case 'Array' :
if(!sel[0]) {return res ;}
for(var i = 0 ; i < selLength ; i++) {
var itemType = sel[i].constructor.name ;
if(itemType == 'TextFrame') {
res.push(sel[i].textRange) ;
} else if(itemType == 'TextRange') {
res.push(sel[i]) ;
}
}
break ;
case 'TextRange' :
res.push(sel) ;
break ;
}
return res ;
}
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.