app.scriptPreferences.version = 4;
var scriptName = "Рамки с фигурными углами";
var scriptVer = " 1.7";
// Умолчания
var myParagraphStyle = "рамка";
var myCornerEffect = "rounded";
var myCornerRadius = "3";
var myStyleLine = "Solid";
var myColorLine = "Black";
var myStrokeWeight = 1;
var myInsetSpacing = "1";
var myInsetSpacing1 = "2.5";
var myLayer, myCounter;
function cornerRound (myTextFrame, myPage) {
myLayer = app.activeDocument.layers.item("Border");
try{
myLayerName = myLayer.name;
if (myClear == true) {
myLayer.remove();
myLayer = app.activeDocument.layers.add({name:"Border"});
}
}
catch (myError){
myLayer = app.activeDocument.layers.add({name:"Border"});
}
// Для каждого абзаца текста
for (myCounter = 0; myCounter < myTextFrame.paragraphs.length; myCounter++) {
myPara = myTextFrame.paragraphs[myCounter];
if (myPara.appliedParagraphStyle.name == myParagraphStyle){
//Определяем ширину колонки
var columnWidth = myTextFrame.textFramePreferences.textColumnFixedWidth;
var myParagraph = myPara.paragraphs[myCounter];
var myLineStart = myPara.lines[0]; // Первая строка указанного параграфа
var myLineEnd = myPara.lines[myPara.lines.length-1];
startline = (myLineStart.baseline - myLineStart.ascent)-0.5;
endline = (myLineEnd.baseline + myLineEnd.descent)+0.5;
l = myPara.horizontalOffset-2.0;
if (myPara.firstLineIndent > 0) {
l = l - myPara.firstLineIndent;
}
var dl= columnWidth;
location = l + dl;
// Вставить текстовый фрейм и применить угловые эффекты
var myNewTextFrame = myPage.textFrames.add();
with (myNewTextFrame) {
strokeWeight = myStrokeWeight;
strokeType = myStyleLine;
strokeColor = myColorLine;
//geometricBounds [y1, x1, y2, x2]
geometricBounds = [startline, l, endline, location];
textFramePreferences.insetSpacing = new Array(myInsetSpacing, myInsetSpacing, myInsetSpacing, myInsetSpacing);
cornerEffect = myCornerEffect;
cornerRadius = myCornerRadius;
}
}
}
}
with (app) {
//Проверяем, что у нас выделено
if ((selection.length == 1)&&((selection[0].constructor.name == "TextFrame") || selection[0].constructor.name == "InsertionPoint")) {
} else {
alert("Необходимо вытелить один текстовый фрейм");
exit();
}
var myDoc = activeDocument;
//Получаем список стилей абзаца
var myStyleNames = new Array();
var mySelectIndexStyle = 0;
for (myCounter = 0; myCounter < myDoc.paragraphStyles.length; myCounter++) {
myStyleNames[myCounter] = myDoc.paragraphStyles[myCounter].name;
if (myStyleNames[myCounter] == myParagraphStyle) {
mySelectIndexStyle = myCounter;
}
}
// Создаем список оформления угла
var myCornerEffectList = new Array ("none", "rounded", "inverse rounded", "inset", "bevel", "fancy");
var myCornerEffectValue = new Array (1852796517, 1667592804, 1667591798, 1667591795, 1667588726, 1667589742);
var mySelectIndexCorner = 0;
for (myCounter = 0; myCounter < myCornerEffectList.length; myCounter++) {
if (myCornerEffectList[myCounter] == myCornerEffect) {
mySelectIndexCorner = myCounter;
}
}
//Получаем список стилей линий
var myStyleLineName = new Array();
var mySelectIndexStyleLine = 0;
for (myCounter = 0; myCounter < myDoc.strokeStyles.length; myCounter++) {
myStyleLineName[myCounter] = myDoc.strokeStyles[myCounter].name;
if (myStyleLineName[myCounter] == myStyleLine) {
mySelectIndexStyleLine = myCounter;
}
}
// Получаем список цветов в публикации
var myColorSwatchesName = new Array();
var mySelectIndexColor = 0;
for (myCounter = 0; myCounter < myDoc.swatches.length; myCounter++) {
myColorSwatchesName[myCounter] = myDoc.swatches.item(myCounter).name;
if (myColorSwatchesName[myCounter] == myColorLine) {
mySelectIndexColor = myCounter;
}
}
// Морда лица
// Создаем диалог
var myDialog = dialogs.add({name:scriptName + scriptVer});
// Подготовка
with (myDialog.dialogColumns.add()) {
with (dialogRows.add().borderPanels.add()) {
with (dialogColumns.add()) {
dialogRows.add().staticTexts.add({staticLabel:"Стиль абзаца"});
dialogRows.add().staticTexts.add({staticLabel:"Оформление углов"});
dialogRows.add().staticTexts.add({staticLabel:"Радиус углов"});
dialogRows.add().staticTexts.add({staticLabel:"отступ от краев рам"});
dialogRows.add().staticTexts.add({staticLabel:"Внутренние отступы"});
dialogRows.add().staticTexts.add({staticLabel:"Стиль линии"});
dialogRows.add().staticTexts.add({staticLabel:"Толщина линии"});
dialogRows.add().staticTexts.add({staticLabel:"Цвет линии"});
}
with (dialogColumns.add()) {
var mySelectStyle = dialogRows.add().dropdowns.add({stringList:myStyleNames, selectedIndex:mySelectIndexStyle});
var mySelectCorner = dialogRows.add().dropdowns.add({stringList:myCornerEffectList, selectedIndex:mySelectIndexCorner});
var mySelectCornerRadius = dialogRows.add().measurementEditboxes.add({editContents:myCornerRadius, editUnits:2053991795}); //
var mySelectInsetSpacing1 = dialogRows.add().measurementEditboxes.add({editContents:myInsetSpacing1, editUnits:2053991795});
var mySelectInsetSpacing = dialogRows.add().measurementEditboxes.add({editContents:myInsetSpacing, editUnits:2053991795});
var mySelectStyleLine = dialogRows.add().dropdowns.add({stringList:myStyleLineName, selectedIndex:mySelectIndexStyleLine});
var mySelectStrokeWeight = dialogRows.add().measurementEditboxes.add({editValue:myStrokeWeight, editUnits:2054188905});
var mySelectColor = dialogRows.add().dropdowns.add({stringList:myColorSwatchesName, selectedIndex:mySelectIndexColor});
var myClearVal = checkboxControls.add({staticLabel:"Удалить слой", checkedState:false});
}
}
with (dialogRows.add()) {
dialogColumns.add().staticTexts.add({staticLabel:""});
}
}
// Показываем
var myResult = myDialog.show();
if (!myResult) {
myDialog.destroy();
exit();
}
myParagraphStyle = myDoc.paragraphStyles[mySelectStyle.selectedIndex].name;
myCornerEffect = myCornerEffectValue[mySelectCorner.selectedIndex];
myCornerRadius = Number (mySelectCornerRadius.editContents);
myStyleLine = myStyleLineName[mySelectStyleLine.selectedIndex];
myStrokeWeight = mySelectStrokeWeight.editValue;
myColorLine = myDoc.swatches.item(myColorSwatchesName[mySelectColor.selectedIndex]);
myInsetSpacing = mySelectInsetSpacing.editContents;
myInsetSpacing1 = mySelectInsetSpacing.editContents;
myClear = myClearVal.checkedState;
//Определяем текст
switch (selection[0].constructor.name) {
case "InsertionPoint":
var myStory = selection[0].parentStory;
break;
case "TextFrame":
var myStory = false;
}
// var myStory = selection[0].parentStory;
if (myStory) {
for (myTextFramesCount = 0; myTextFramesCount < myStory.textFrames.length; myTextFramesCount++) {
var myTextFrame = myStory.textFrames[myTextFramesCount];
var pageNum = myTextFrame.parent.id;
var myPage = activeDocument.pages.itemByID(pageNum);
cornerRound (myTextFrame, myPage)
}
}
else {
myTextFrame = selection[0];
var pageNum = myTextFrame.parent.id;
var myPage = activeDocument.pages.itemByID(pageNum);
cornerRound (myTextFrame, myPage)
}
}