Copy link to clipboard
Copied
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
* @author sttk3.com
* @copyright © 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
...
Copy link to clipboard
Copied
Not enough information.
But: try to apply the normal paragraph style to all paragraphs.
Copy link to clipboard
Copied
It can make selected text a default attribute. Do you mean that?
/**
* @File make selected text default attributes
* @version 1.0.0
* @author sttk3.com
* @copyright © 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]
var defaultCharacterStyle = doc.characterStyles[0] ;
// reset text style
for(var i = 0 ; i < targetRangeLength ; i++) {
defaultCharacterStyle.applyTo(targetRanges[i], 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 ;
}
Copy link to clipboard
Copied
Thank you so much, you are almost close to my expectectation. and the script works well while no predefined text styles I mean Character and Paragraph style. but when I run this script on the text where applied predefined text styles. the result come different. it doesn't reset font and color as normal below is the screenshot of it
Copy link to clipboard
Copied
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
* @author sttk3.com
* @copyright © 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 ;
}
Copy link to clipboard
Copied
awesome! you are great. This works perfectly as I was expecting. Thank you so much once again
Copy link to clipboard
Copied
awesome! you are great. This works perfectly as I was expecting. Thank you so much once again