Copy link to clipboard
Copied
Hi Pros..
I tried to Write this script to remvoe Unused Object Styles but it not working!, i dont know why, maybe i miss something..
//Remove Unused Object Styles
removeUnusedObjStyles();
function removeUnusedObjStyles() {
var ObjStyles, found,
doc = app.activeDocument,
ObjStyles = doc.objectStyles;
for (var i = ObjStyles.length - 1; i >= 1; i--) { // skip default style: [None]
try {
ObjStyles = ObjStyles[i];
app.findObjectPreferences = app.changeObjectPreferences = NothingEnum.NOTHING;
app.findObjectPreferences.appliedObjectStyles = ObjStyles;
found = doc.findObject();
if (found.length == 0) {
ObjStyles.remove();
}
}
catch(err) {
var g
g.WriteToFile(doc.name + " - " + err.message + ", line: " + err.line);
}
}
app.findObjectPreferences = app.changeObjectPreferences = NothingEnum.NOTHING;
}
Please Help fixing the code
Best
medo
You're setting ObjStyles to the iterated style within the loop (ObjStyles = ObjStyles[i]). This is probably throwing things off. Give the individual element its own variable.
Copy link to clipboard
Copied
Hello.
Your code seems to work fine except for what's shown below, I'm not sure what you're trying to achieve with this.
var g
g.WriteToFile(doc.name + " - " + err.message + ", line: " + err.line);
Regards,
Mike
Copy link to clipboard
Copied
it showing error if happend but i get rid of it, thank you
Copy link to clipboard
Copied
You're setting ObjStyles to the iterated style within the loop (ObjStyles = ObjStyles[i]). This is probably throwing things off. Give the individual element its own variable.
Copy link to clipboard
Copied
Thank you very much,, now the code working, the final code is :
//Remove Unused Object Styles
removeUnusedObjStyles();
function removeUnusedObjStyles() {
var ObjStyles, found,
doc = app.activeDocument,
ObjStyles = doc.objectStyles;
for (var i = ObjStyles.length - 1; i >= 1; i--) { // skip default style: [None]
app.findObjectPreferences = app.changeObjectPreferences = NothingEnum.NOTHING;
app.findObjectPreferences.appliedObjectStyles = ObjStyles[i];
found = doc.findObject();
if (found.length == 0) {
ObjStyles[i].remove();
}
}
app.findObjectPreferences = app.changeObjectPreferences = NothingEnum.NOTHING;
}
Best
medos20