/* Скрипт для пакетного или единичного поворота документа
Корректно работает, если в документе содержится один артборд.
*/
/* Окно меню с выбором вырианта работы:
поворачиваем активный документ или все документы в выбранной папке */
var doc = app.activeDocument;
var WorkPath = doc.path;
var Metka='Current';
var Rotate=[];
var Rotation;
var files;
var sourceFile;
var SaveOptionPdf = new PDFSaveOptions();
function RotateDoc () {
var doc = app.activeDocument;
var ArtBoardSize = doc.artboards[0].artboardRect;
var ParentLayer = doc.layers;
var LockedLayers = [];
var UnvisibleLayers = [];
var ArtBoardWidth=Math.abs(ArtBoardSize[2]-ArtBoardSize[0]);
var ArtBoardHeight=Math.abs(ArtBoardSize[3]-ArtBoardSize[1]);
var dX= (ArtBoardSize[2]+ ArtBoardSize[0])/2;
var dY = (ArtBoardSize[3]+ ArtBoardSize[1])/2;
doc.artboards[0].artboardRect = [-ArtBoardWidth/2, ArtBoardHeight/2, ArtBoardWidth/2, -ArtBoardHeight/2];
if (Rotation!=180) {
doc.artboards[0].artboardRect = [-ArtBoardHeight/2, ArtBoardWidth/2, ArtBoardHeight/2, -ArtBoardWidth/2];
}
for (i=0; i<doc.layers.length; i++) {
if (doc.layers[i].locked == true) {
LockedLayers[i] = doc.layers[i];
// alert (LockedLayers[i])
}
if (doc.layers[i].visible == false) {
UnvisibleLayers[i] = doc.layers[i]
}
doc.layers[i].locked = false;
doc.layers[i].visible = true;
for (k=0; k<doc.layers[i].pageItems.length; k++) {
if (doc.layers[i].pageItems[k].parent == ParentLayer[i]) {
doc.layers[i].pageItems[k].translate(-dX, -dY);
doc.layers[i].pageItems[k].rotate(Rotation,true, true, true, true, Transformation.DOCUMENTORIGIN);
}
}
// if (doc.layers[i].name == 'knife') { doc.layers[i].locked = true }
}
for (i=0; i<LockedLayers.length; i++) {
if (LockedLayers[i]!=null) {
LockedLayers[i].locked = true;
}
}
for (i=0; i<UnvisibleLayers.length; i++) {
if (UnvisibleLayers[i]!=null) {
UnvisibleLayers[i].visible = false;
}
}
}
// alert (WorkPath);
var WorkOptions = new Window ('dialog', 'Повернуть документ');
var AllFiles = WorkOptions.add ('group');
AllFiles.orientation = 'row';
var AllFilesTxt = AllFiles.add ('statictext', undefined, 'Все документы в этой папке');
var ChAllFiles = AllFiles.add ('checkbox');
var RotateGroup = WorkOptions.add ('group');
RotateGroup.orientation = "row";
Rotate[0] = RotateGroup.add ('button', [0,0, 54,18], '90\u00b0');
Rotate[0].active = true;
Rotate[1] = RotateGroup.add ('button', [0,0, 54,18], '180\u00b0');
Rotate[2] = RotateGroup.add ('button', [0,0, 54,18], '270\u00b0');
Rotate[0].onClick = function () {Rotation = 90; WorkOptions.close () }
Rotate[1].onClick = function () {Rotation = 180; WorkOptions.close () }
Rotate[2].onClick = function () {Rotation = 270; WorkOptions.close () }
WorkOptions.show ();
//alert (Rotation);
if (ChAllFiles.value == true) {
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
files = new Array();
files = WorkPath.getFiles('*.pdf');
// alert (files.length);
for (a=0; a<files.length; a++) {
sourceFile = app.open(files[a]);
doc = app.activeDocument;
NameFiles = doc.fullName;
// alert (NameFiles);
sourceFile = RotateDoc();
doc.saveAs(NameFiles, SaveOptionPdf);
doc.close(SaveOptions.DONOTSAVECHANGES);
}
}
else { doc = RotateDoc ()}