Copy link to clipboard
Copied
Hi,
I need to delete unused paragraph styles in document using action, until selection of unused style count is 0.
I saw the below url in this forum. Can i do this using action???
remove unused styles in one action...
Thanks in advance,
Sudha K
Hi,
It will not make any change. However, please create pdf and compare with old one to check this. If my answer is correct, please mark it as correct answer so that it will be reference to others.
Thanks
K Ramesh
Copy link to clipboard
Copied
Hi,
Please use this script. It might be helpful to you.
| var myDoc = app.activeDocument; | |
| var myParStyles = myDoc.paragraphStyles; | |
| var myCharStyles = myDoc.characterStyles; | |
| for (i = myParStyles.length-1; i >= 2; i-- ){ | |
| removeUnusedParaStyle(myParStyles) | |
| } | |
| for (i = myCharStyles.length-1; i >= 1; i-- ){ | |
| removeUnusedCharStyle(myCharStyles) | |
| } | |
| function removeUnusedParaStyle(myPaStyle) { | |
| app.findTextPreferences = app.changeTextPreferences=null; | |
| app.findTextPreferences.appliedParagraphStyle = myPaStyle; | |
| var myFoundStyles = myDoc.findText(); | |
| if (myFoundStyles == 0) { | |
| myPaStyle.remove(); | |
| } | |
| app.findTextPreferences = app.changeTextPreferences=null; | |
| } | |
| function removeUnusedCharStyle(myChStyle) { | |
| app.findTextPreferences = app.changeTextPreferences=null; | |
| app.findTextPreferences.appliedCharacterStyle = myChStyle; | |
| var myFoundStyles = myDoc.findText(); | |
| if (myFoundStyles == 0) { | |
| myChStyle.remove(); | |
| } | |
| app.findTextPreferences = app.changeTextPreferences=null; | |
| } |
alert(" All Unused Styles removed Successfully");
Copy link to clipboard
Copied
Hi,
Thank you... Can we do this using menu action??
I can remove styles using menu action using the below code.
try{
app.menuActions.itemByID(8474).invoke();
app.menuActions.itemByID(8451).invoke();
}catch(e){
app.menuActions.itemByID(8450).invoke();
app.menuActions.itemByID(8474).invoke();
app.menuActions.itemByID(8451).invoke();
}
But my prob is the dialog box appeared when run the code. How can i escape that dialog without mapping style??

- Sudha K
Copy link to clipboard
Copied
Hi,
if Unused style is "based on" to another style, it will ask replace any style with unused style. Please find the style in which the "based on" style(unused) has been used and redefine it. Then you can run script. It will not show the dialog to replace any style. I hope this will work.
Thanks
K Ramesh
Copy link to clipboard
Copied
Hi,
Thank you. yes its working now.
If i change based on to "[No Paragraph Style]" and Next style to "[Basic Paragraph]", will it make any changes in document???
- Sudha K
Copy link to clipboard
Copied
Hi,
It will not make any change. However, please create pdf and compare with old one to check this. If my answer is correct, please mark it as correct answer so that it will be reference to others.
Thanks
K Ramesh
Copy link to clipboard
Copied
Hi,
Thank you...
Find more inspiration, events, and resources on the new Adobe Community
Explore Now