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

How to Clear Text formatting by script?

Engaged ,
Jul 21, 2023 Jul 21, 2023

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

TOPICS
Scripting

Views

449

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 , Jul 21, 2023 Jul 21, 2023

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 
...

Votes

Translate

Translate
Adobe
Community Expert ,
Jul 21, 2023 Jul 21, 2023

Copy link to clipboard

Copied

Not enough information.

 

But: try to apply the normal paragraph style to all paragraphs.

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 ,
Jul 21, 2023 Jul 21, 2023

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 ;
}

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
Engaged ,
Jul 21, 2023 Jul 21, 2023

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

 

jkhakase_0-1689939660055.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 ,
Jul 21, 2023 Jul 21, 2023

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 ;
}

 

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
New Here ,
Jul 21, 2023 Jul 21, 2023

Copy link to clipboard

Copied

awesome! you are great. This works perfectly as I was expecting. Thank you so much once again

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
Engaged ,
Jul 21, 2023 Jul 21, 2023

Copy link to clipboard

Copied

LATEST

awesome! you are great. This works perfectly as I was expecting. Thank you so much once again

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