var docRef = app.activeDocument;
var Koef_mm = 2.834645
var Szer_1P = prompt('Wpisż znaczenie krótkiej strony', 100) ;
var Szer_2P = prompt('Wpisż znaczenie długej strony?', 100);
var Wys_1P = prompt('Wpisż wysokość kartonu?', '');
var Szer_kr = (Koef_mm*Szer_1P)
var Szer_dl = (Koef_mm*Szer_2P)
var Wysokość = (Koef_mm*Wys_1P)
var Wysokość_klapki = (Szer_kr/2)
var noColor = new NoColor();
// measurement line color
var color = new CMYKColor;
color.cyan = 100;
color.black = 35;
// gap between measurement lines and object
var gap = 10;
// size of measurement lines.
var size = 30;
// number of decimal places
var decimals = 0;
// pixels per inch
var dpi = 72;
/**
Start the spec
*/
try {
var speclayer =doc.layers['spec'];
} catch(err) {
var speclayer = doc.layers.add();
speclayer.name = 'spec';
}
if ( app.documents.length > 0 ) {
var spotCount = app.activeDocument.spots.length;
if (spotCount > 0) {
app.activeDocument.spots.removeAll();
}
}
if ( app.documents.length > 0 ) {
var spotCount = app.activeDocument.spots.length;
if (spotCount > 0) {
app.activeDocument.spots.removeAll();
}
}
if ( app.documents.length > 0) {
var doc = app.activeDocument;
var newSpot = doc.spots.add ();
// Define the new color value
var newColor = new CMYKColor();
newColor.magenta = 100;
newColor.yellow = 100;
newSpot.name = "SIATKA";
newSpot.colorType = ColorModel.SPOT;
newSpot.color = newColor;
var newSpotColor = new SpotColor();
newSpotColor.spot = newSpot;
newSpotColor.tint = 100;
}
function specSingle( bound ) {
// width and height
var w = bound[2]-bound[0];
var h = bound[1]-bound[3];
// a & b are the horizontal or vertical positions that change
// c is the horizontal or vertical position that doesn't change
var a = bound[0];
var b = bound[2];
var c = bound[1];
// xy='x' (horizontal measurement), xy='y' (vertical measurement)
var xy = 'x';
// a direction flag for placing the measurement lines.
var dir = 1;
a = bound[0];
b = bound[2];
c = bound[1];
xy = 'x';
dir = 1;
// create the measurement lines
var lines = new Array();
// horizontal measurement
if (xy=='x') {
// 2 vertical lines
lines[0]= new Array( new Array(a, c+(gap)*dir) );
lines[0].push ( new Array(a, c+(gap+size)*dir) );
lines[1]= new Array( new Array(b, c+(gap)*dir) );
lines[1].push( new Array(b, c+(gap+size)*dir) );
// 1 horizontal line
lines[2]= new Array( new Array(a, c+(gap+size/2)*dir ) );
lines[2].push( new Array(b, c+(gap+size/2)*dir ) );
// create text label
var t = specLabel( w, (a+b)/2, lines[0][1][1] );
}
// draw the lines
var specgroup = new Array(t);
for (var i=0; i<lines.length; i++) {
var p = doc.pathItems.add();
p.setEntirePath ( lines[i] );
setLineStyle( p, color );
specgroup.push( p );
}
group(speclayer, specgroup );
}
/**
Create a text label that specify the dimension
*/
function specLabel( val, x, y) {
var t = doc.textFrames.add();
t.textRange.characterAttributes.size = 18;
t.textRange.characterAttributes.alignment = StyleRunAlignmentType.center;
var v = val;
switch (doc.rulerUnits) {
case RulerUnits.Inches:
v = val/dpi;
v = v.toFixed (decimals);
break;
case RulerUnits.Centimeters:
v = val/(dpi/2.54);
v = v.toFixed (decimals);
break;
case RulerUnits.Millimeters:
v = val/(dpi/25.4);
v = v.toFixed (decimals);
break;
case RulerUnits.Picas:
v = val/(dpi/6);
var vd = v - Math.floor (v);
vd = 12*vd;
v = Math.floor(v)+'p'+vd.toFixed (decimals);
break;
default:
v = v.toFixed (decimals);
}
t.contents = v;
t.top = y;
t.left = x;
return t;
}
function setLineStyle(path, color) {
path.filled = false;
path.stroked = true;
path.strokeColor = color;
path.strokeWidth = 0.5;
return path;
}
/**
* Group items in a layer
*/
function group( layer, items, isDuplicate) {
// create new group
var gg = layer.groupItems.add();
// add to group
// reverse count, because items length is reduced as items are moved to new group
for(var i=items.length-1; i>=0; i--) {
if (items[i]!=gg) { // don't group the group itself
if (isDuplicate) {
newItem = items[i].duplicate (gg, ElementPlacement.PLACEATBEGINNING);
} else {
items[i].move( gg, ElementPlacement.PLACEATBEGINNING );
}
}
}
return gg;
}
// Srodek kartonu
var Klap_smal1 = docRef.pathItems.rectangle(100, 100, Szer_kr, Wysokość);
Klap_smal1.fillColor = noColor;
Klap_smal1.strokeColor = newColor;
specSingle( Klap_smal1.geometricBounds);
redraw();
var Klap_big1 = docRef.pathItems.rectangle(100, 100+Szer_kr, Szer_dl, Wysokość);
Klap_big1.fillColor = noColor;
Klap_big1.strokeColor = newColor;
specSingle( Klap_big1.geometricBounds );
redraw();
var Klap_smal2 = docRef.pathItems.rectangle(100, 100+Szer_kr+Szer_dl, Szer_kr, Wysokość);
Klap_smal2.fillColor = noColor;
Klap_smal2.strokeColor = newColor;
specSingle( Klap_smal2.geometricBounds );
redraw();
var Klap_big2 = docRef.pathItems.rectangle(100, 100+Szer_kr+Szer_dl+Szer_kr, Szer_dl, Wysokość);
Klap_big2.fillColor = noColor;
Klap_big2.strokeColor = newColor;
specSingle( Klap_big2.geometricBounds );
redraw();
var Klap_klej = docRef.pathItems.rectangle(100, 65, 35, Wysokość);
Klap_klej.fillColor = noColor;
Klap_klej.strokeColor = newColor;
specSingle( Klap_klej.geometricBounds );
redraw();
// Dolne Klapki
var Klap_smal1_1 = docRef.pathItems.rectangle(100+Wysokość_klapki, 100 , Szer_kr-5.6695, Wysokość_klapki);
Klap_smal1_1.fillColor = noColor;
Klap_smal1_1.strokeColor = newColor;
redraw();
var Klap_big1_1 = docRef.pathItems.rectangle(100+Wysokość_klapki, 105.6695+Szer_kr, Szer_dl-11.339, Wysokość_klapki);
Klap_big1_1.fillColor = noColor;
Klap_big1_1.strokeColor = newColor;
redraw();
var Klap_smal1_2 = docRef.pathItems.rectangle(100+Wysokość_klapki, 105.6695+Szer_kr+Szer_dl, Szer_kr-11.339, Wysokość_klapki);
Klap_smal1_2.fillColor = noColor;
Klap_smal1_2.strokeColor = newColor;
redraw();
var Klap_big1_2 = docRef.pathItems.rectangle(100+Wysokość_klapki, 105.6695+Szer_kr+Szer_dl+Szer_kr, Szer_dl-5.6695, Wysokość_klapki);
Klap_big1_2.fillColor = noColor;
Klap_big1_2.strokeColor = newColor;
redraw();
// Gorne Klapki
var Klap_smal2_1 = docRef.pathItems.rectangle(100-Wysokość, 100, Szer_kr-5.6695, Wysokość_klapki);
Klap_smal2_1.fillColor = noColor;
Klap_smal2_1.strokeColor = newColor;
redraw();
var Klap_big2_1 = docRef.pathItems.rectangle(100-Wysokość, 105.6695+Szer_kr, Szer_dl-11.339, Wysokość_klapki);
Klap_big2_1.fillColor = noColor;
Klap_big2_1.strokeColor = newColor;
redraw();
var Klap_smal2_2 = docRef.pathItems.rectangle(100-Wysokość, 105.6695+Szer_kr+Szer_dl, Szer_kr-11.339, Wysokość_klapki);
Klap_smal2_2.fillColor = noColor;
Klap_smal2_2.strokeColor = newColor;
redraw();
var Klap_big2_2 = docRef.pathItems.rectangle(100-Wysokość, 105.6695+Szer_kr+Szer_dl+Szer_kr, Szer_dl-5.6695, Wysokość_klapki);
Klap_big2_2.fillColor = noColor;
Klap_big2_2.strokeColor = newColor;
redraw();