var strtRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.CM;
var aDoc = app.activeDocument;
var cm = aDoc.resolution /2.539861719;
var H = aDoc.height;
var W = aDoc.width;
var dlg = new Window('dialog', 'Введите параметры');
dlg.frameLocation = [200, 200];
dlg.msgPnl = dlg.add('panel', undefined, 'Параметры');
dlg.msgPnl.alignChildren = "right";
dlg.msgPnl.K = dlg.msgPnl.add('group');
dlg.msgPnl.B = dlg.msgPnl.add('group');
dlg.msgPnl.msgHeight = dlg.msgPnl.add('group');
dlg.msgPnl.selectFolder = dlg.msgPnl.add('group');
with (dlg.msgPnl) {
K.st = K.add('statictext', undefined, 'Количество равных сегментов:');
K.et = K.add('edittext', undefined, '3');
K.et.preferredSize = [40,20];
B.st = B.add('statictext', undefined, 'Нахлест:');
B.et = B.add('edittext', undefined, '1');
B.et.preferredSize = [40,20];
};
var bolUserCancel = false;
dlg.buttons2 = dlg.add('group');
dlg.buttons2.btnClose = dlg.buttons2.add("button",undefined , "Ok" );
dlg.buttons2.btnClose.onClick = function() { this.parent.close(0); };
dlg.buttons2.btnCancel = dlg.buttons2.add("button",undefined , "Cancel" );
dlg.buttons2.btnCancel.onClick = function() { bolUserCancel = true; this.parent.close(0); };
dlg.show();
var K = parseFloat (dlg.msgPnl.K.et.text);
var B = parseFloat (dlg.msgPnl.B.et.text);
delete dlg;
clearGuides();
var D = W+B*(K-1)
var C = D/K
var M = aDoc.resolution/72
var foreColor = new SolidColor();
foreColor.cmyk.cyan = 0;
foreColor.cmyk.magenta = 0;
foreColor.cmyk.yellow = 0;
foreColor.cmyk.black = 40;
app.foregroundColor = foreColor;
for (var iQ=1; iQ < K; iQ++) {
guideLine(cm*(iQ*(C-B)), 'Vert' ,'#Pxl');
guideLine(cm*(iQ*C-(iQ-1)*B), 'Vert' ,'#Pxl');
drawLine (cm*(iQ*(C-B))/M, 0*cm, cm*(iQ*(C-B))/M, 1*cm/M, 1);
drawLine (cm*(iQ*(C-B))/M, H*cm/M, cm*(iQ*(C-B))/M, (H-1)*cm/M, 1);
}
function guideLine(position, type,unit) {
var desc = new ActionDescriptor();
var desc2 = new ActionDescriptor();
desc2.putUnitDouble( charIDToTypeID('Pstn'), charIDToTypeID(unit), position);
desc2.putEnumerated( charIDToTypeID('Ornt'), charIDToTypeID('Ornt'), charIDToTypeID(type) );
desc.putObject( charIDToTypeID('Nw '), charIDToTypeID('Gd '), desc2 );
executeAction( charIDToTypeID('Mk '), desc, DialogModes.NO );
};
function clearGuides() {
var id556 = charIDToTypeID( "Dlt " );
var desc102 = new ActionDescriptor();
var id557 = charIDToTypeID( "null" );
var ref70 = new ActionReference();
var id558 = charIDToTypeID( "Gd " );
var id559 = charIDToTypeID( "Ordn" );
var id560 = charIDToTypeID( "Al " );
ref70.putEnumerated( id558, id559, id560 );
desc102.putReference( id557, ref70 );
executeAction( id556, desc102, DialogModes.NO );
};
function drawLine(startX, startY, endX, endY, lineWidth) {
var idDraw = charIDToTypeID( "Draw" );
var desc5 = new ActionDescriptor();
var idShp = charIDToTypeID( "Shp " );
var desc6 = new ActionDescriptor();
var idStrt = charIDToTypeID( "Strt" );
var desc7 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idRlt = charIDToTypeID( "#Rlt" );
desc7.putUnitDouble( idHrzn, idRlt, startX );
var idVrtc = charIDToTypeID( "Vrtc" );
var idRlt = charIDToTypeID( "#Rlt" );
desc7.putUnitDouble( idVrtc, idRlt, startY );
var idPnt = charIDToTypeID( "Pnt " );
desc6.putObject( idStrt, idPnt, desc7 );
var idEnd = charIDToTypeID( "End " );
var desc8 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idRlt = charIDToTypeID( "#Rlt" );
desc8.putUnitDouble( idHrzn, idRlt, endX );
var idVrtc = charIDToTypeID( "Vrtc" );
var idRlt = charIDToTypeID( "#Rlt" );
desc8.putUnitDouble( idVrtc, idRlt, endY );
var idPnt = charIDToTypeID( "Pnt " );
desc6.putObject( idEnd, idPnt, desc8 );
var idWdth = charIDToTypeID( "Wdth" );
var idPxl = charIDToTypeID( "#Pxl" );
desc6.putUnitDouble( idWdth, idPxl, lineWidth );
var idLn = charIDToTypeID( "Ln " );
desc5.putObject( idShp, idLn, desc6 );
var idAntA = charIDToTypeID( "AntA" );
desc5.putBoolean( idAntA, false );
executeAction( idDraw, desc5, DialogModes.NO );
}
app.preferences.rulerUnits = strtRulerUnits;