sorry, I get the similar error:

ArrayCompress=function(array){
var str = array.sort().join('\r')+'\r'
str = str.replace(/([^\r]+\r)(\1)+/g,'$1')
str = str.replace(/\r$/,'')
return str.split('\r')
}
IsInArray = function (item,array){
for(var i=0;i<array.length;i++){
if(array == item){return true;}
}
return false;
}
var doc = app.documents[0];
var styles = doc.stories.everyItem().paragraphs.everyItem().appliedParagraphStyle;
try{
styles = styles.concat(doc.stories.everyItem().footnotes.everyItem().paragraphs.everyItem().appliedParagraphStyle);
}catch(e){}
try{
styles = styles.concat(doc.stories.everyItem().tables.everyItem().cells.everyItem().paragraphs.everyItem().appliedParagraphStyle);
}catch(e){}
var names = [];
for(var i=0;i<styles.length;i++){
names = styles.name;
}
names = ArrayCompress(names);
// var allStyles = doc.allParagraphStyles;
var allStyles = doc.paragraphStyleGroups.itemByName("APPENDIX").paragraphStyles;
for(var i=allStyles.length-1;i>=0;i--){
if(IsInArray(allStyles.name,names)){
allStyles.splice(i,1);
}
}
alert(allStyles.length + " unused styles");
If you want test, here is my Indesign: Download
Thanks!
HI,
I apologies I thought the solution was easier that it turned out to be, please find the code below which should do what is required.
ArrayCompress=function(array){
var str = array.sort().join('\r')+'\r'
str = str.replace(/([^\r]+\r)(\1)+/g,'$1')
str = str.replace(/\r$/,'')
return str.split('\r')
}
IsInArray = function (item,array){
for(var i=0;i<array.length;i++){
if(array == item){return true;}
}
return false;
}
var doc = app.documents[0];
var styles = doc.stories.everyItem().paragraphs.everyItem().appliedParagraphStyle;
try{
styles = styles.concat(doc.stories.everyItem().footnotes.everyItem().paragraphs.everyItem().appliedParagraphStyle);
}catch(e){}
try{
styles = styles.concat(doc.stories.everyItem().tables.everyItem().cells.everyItem().paragraphs.everyItem().appliedParagraphStyle);
}catch(e){}
var names = [];
for(var i=0;i<styles.length;i++){
names = styles.name;
}
names = ArrayCompress(names);
var allStyles = doc.allParagraphStyles;
for(var i=allStyles.length-1;i>=0;i--){
if(IsInArray(allStyles.name,names)){ allStyles.splice(i,1); }
}
var appendixStyles = doc.paragraphStyleGroups.itemByName("APPENDIX").paragraphStyles;
var stylesToRemove = [];
for ( var k = 0; k < allStyles.length; k++)
{
for ( var l = 0; l < appendixStyles.length; l++)
{
if ( allStyles.name == appendixStyles.name)
{
stylesToRemove.push ( appendixStyles);
}
}
}
for ( var p = stylesToRemove.length-1; p > 0; p--)
{
stylesToRemove
.remove();
}
I have left the original code alone this time, to get a list of all the paragraph styles that are not needed, then I have compared that this to the list of paragraph styles in the paragraph style group you wanted, then finally I have removed the styles, I have done it like this as it can get really confusing to delete styles while still working out which styles you need.
Hope this helps.
Malcolm