var doc = app.activeDocument;
var psList = [];
var psID = [];
var osList = [];
var osID = [];
getStyles("paragraphStyle","psList","psID");
getStyles("objectStyle","osList","osID");
var w = new Window("dialog");
w.alignChildren = "left";
var g = w.add("group");
g.add("statictext{text:\"Найти абзацный стиль: \",characters:25}");
var selStyle = g.add("dropdownlist",undefined,psList);
var g1 = w.add("group");
g1.add("statictext{text:\"Назначить объектный стиль: \",characters:25}");
var applyOStyle = g1.add("dropdownlist",undefined,osList);
w.add("button",undefined,"OK");
if (w.show()!=1) exit();
app.findGrepPreferences = null;
app.findGrepPreferences.appliedParagraphStyle = doc.paragraphStyles.itemByID(psID[selStyle.selection.index]);
var f = doc.findGrep();
for (i=0;i<f.length;i++){
f[i].parentStory.textContainers[0].appliedObjectStyle = doc.objectStyles.itemByID(osID[applyOStyle.selection.index]);
}
function getStyles(styleType,styleList,styleID){
var s = styleList+" = doc."+styleType+"s.everyItem().name;\n";
s += styleID+" = doc."+styleType+"s.everyItem().id;\n";
s += styleType+"G = doc."+styleType+"Groups;\n";
s += "for (i=0; i<"+styleType+"G.length; i++){\n";
s += "for (j=0; j<"+styleType+"G[i]."+styleType+"s.length; j++){\n";
s += styleList+".push("+styleType+"G[i]."+styleType+"s[j].name + \" (\"+"+styleType+"G[i].name+\")\");\n";
s += styleID+".push("+styleType+"G[i]."+styleType+"s[j].id);\n";
s += "}}";
app.doScript(s,ScriptLanguage.JAVASCRIPT);
}