Copy link to clipboard
Copied
i was trying to remove unused paragraph styles the same way as indesign do it while keeping in mind the basedon property but it is still not working properly
here is my code and i dont know the problem
var myParStyles = app.activeDocument.paragraphStyles;
var flag = true;
for (i = myParStyles.length-1; i >= 2; i--){
app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences.appliedParagraphStyle = myParStyles;
var myFoundStyles = app.activeDocument.findText();
if (myFoundStyles == 0) {
for (x = myParStyles.length-1; x >= 2; x--){
if (myParStyles
app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences.appliedParagraphStyle = myParStyles
var myFoundStyles1 = app.activeDocument.findText();
if (myFoundStyles1 == 0) {myParStyles.remove();}
flag = false; break;}}
if (flag) {myParStyles.remove();}}}
alert("Done");
Hi,
I made the below script in a hurry and did not test extensively, but it works for me...
var myDoc = app.activeDocument;
var myParStyles = myDoc.paragraphStyles;
for (i = myParStyles.length-1; i >= 2;i-- )
{
var itr=0;
itr=removeUnusedParaStyle(myParStyles);
alert(myParStyles.name);
if(itr==1)
myParStyles.remove();
}
function removeUnusedParaStyle(myPaStyle)
{
app.findTextPreferences = app.changeTextPreferences=null;
app.findTextPreferences.appliedParagraphStyle = myPaStyle;
...Copy link to clipboard
Copied
Hi,
I made the below script in a hurry and did not test extensively, but it works for me...
var myDoc = app.activeDocument;
var myParStyles = myDoc.paragraphStyles;
for (i = myParStyles.length-1; i >= 2;i-- )
{
var itr=0;
itr=removeUnusedParaStyle(myParStyles);
alert(myParStyles.name);
if(itr==1)
myParStyles.remove();
}
function removeUnusedParaStyle(myPaStyle)
{
app.findTextPreferences = app.changeTextPreferences=null;
app.findTextPreferences.appliedParagraphStyle = myPaStyle;
var myFoundStyles = myDoc.findText();
if (myFoundStyles == 0)
{
for (var k = myParStyles.length-1; k >= 2; k-- )
{
if (myParStyles
return 0;
}
return 1;
}
return 0;
}
In the script, a paragraph style "p" will be considered unused when
1. Document has no text with that style applied
2. And no other style is based on "p"
InDesign however considers a style "p" unused when no other style is based on "p"
Indesign will consider a style "p" used, even if an empty paragraph (with no text) has that style applied.
Example: If i create 2 style p1 and p2 and make a blank frame with p1 selected, then InDesign will consider only p2 unused. The script above will consider both p1 and p2 unused.
Let me know if this helps.
-Aman
Copy link to clipboard
Copied
many thanks to you i think it works fine now, but is there any way to improve it or it is fine as it is