var doc = app.activeDocument;
var SaveOptionEPS = new EPSSaveOptions();
var SaveOptionPDF = new PDFSaveOptions();
var Texts = [];
var SelectTxt = [];
var myFile = File.openDialog ('Select file', '*.csv;', false); // выбираем файл базы данных
myFile.open('read');
var strValue = new Array();
i=0;
while (!myFile.eof) {
strValue[i] = myFile.readln();
i++;
}
for (i=0; i<strValue.length; i++) {
Texts[i] = strValue[i].split(';')
}
var mySelected = [];
var k=0
for (i=0; i<doc.pageItems.length; i++) {
if (doc.pageItems[i].selected ==true&&doc.pageItems[i].typename=='TextFrame') {
mySelected[k] = doc.pageItems[i];
k=k+1 }
}
var Dialog = myInput();
function myInput () {
var Dlg = new Window ('dialog', 'Переменные данные');
var Panel = Dlg.add ('panel');
for (i=0; i<mySelected.length; i++) {
var DlgGrp = Panel.add ('group');
DlgGrp.add ('statictext', [0, 0, 112, 24], mySelected[i].contents)
SelectTxt[i] = DlgGrp.add ('dropdownlist', [0, 0, 112, 24], Texts[0])
}
var SaveOpt = Dlg.add ('panel');
SaveOpt.alignChildren = 'left';
// SaveOptions.orientation = 'row';
var FileFormat = SaveOpt.add ('group');
FileFormat.add ('statictext', undefined, 'Сохранить файлы как:');
FileFormat.add ('radiobutton', undefined, 'PDF');
FileFormat.add ('radiobutton', undefined, 'EPS');
FileFormat.children[1].value = true;
var FileName = SaveOpt.add ('group');
FileName.add ('checkbox', undefined, 'Взять имя файла из базы');
FileName.add ('dropdownlist', [0, 0, 80, 24], Texts[0]);
FileName.children[1].enabled = false;
FileName.children[0].onClick = function () {
if (FileName.children[0].value == true) {FileName.children[1].enabled = true}
else {FileName.children[1].enabled = false}
}
var Confirm = Dlg.add ('group');
Confirm.add ('button', undefined, 'Cancel', {name: 'Cancel'});
Confirm.add ('button', undefined, 'Ok', {name: 'Ok'});
if (Dlg.show ()==1) {
if (FileFormat.children[1].value==true) {
var SaveOptions = SaveOptionPDF}
else {SaveOptions = SaveOptionEPS}
for (i=0; i<strValue.length; i++) {
if (FileName.children[0].value == true) {var myFile = File (doc.path+'/'+ Texts[i][FileName.children[1].selection.index])}
else { myFile = File (doc.path+'/'+(i+1)) }
for (k=0; k<SelectTxt.length; k++) {
mySelected[k].contents = Texts[i][SelectTxt[k].selection.index];
}
doc.saveAs(myFile, SaveOptions)
}
}
}