Copy link to clipboard
Copied
The script calculates how many times it has to move the marks so that the space between them is 50 and the first and last has been shifted by the same value from the edge. The problem is that, for example, with a file having 500x100 and 100DPI everything is OK, but with a file 500x100 with 20 dpi, the last marker moves too far. How to fix it ?
var selectedWeld = 5;
var eyeletTop = 50;
var firstShift = selectedWeld / 2 ;
app.preferences.rulerUnits = Units.CM;
var docRef = app.activeDocument;
var layerRef = docRef.activeLayer;
app.displayDialogs = DialogModes.NO;
var strtRulerUnits = app.preferences.rulerUnits;
var strtTypeUnits = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.CM;
app.preferences.typeUnits = TypeUnits.MM;
docRef.flatten();
//////////////////////// stroke ////////////////////////////////////
activeDocument.selection.selectAll();
var idStrk = charIDToTypeID( "Strk" );
var desc100 = new ActionDescriptor();
var idWdth = charIDToTypeID( "Wdth" );
desc100.putInteger( idWdth, 1 );
var idLctn = charIDToTypeID( "Lctn" );
var idStrL = charIDToTypeID( "StrL" );
var idCntr = charIDToTypeID( "Cntr" );
desc100.putEnumerated( idLctn, idStrL, idCntr );
var idOpct = charIDToTypeID( "Opct" );
var idPrc = charIDToTypeID( "#Prc" );
desc100.putUnitDouble( idOpct, idPrc, 100.000000 );
var idMd = charIDToTypeID( "Md " );
var idBlnM = charIDToTypeID( "BlnM" );
var idNrml = charIDToTypeID( "Nrml" );
desc100.putEnumerated( idMd, idBlnM, idNrml );
var idClr = charIDToTypeID( "Clr " );
var desc101 = new ActionDescriptor();
var idCyn = charIDToTypeID( "Cyn " );
desc101.putDouble( idCyn, 75.290000 );
var idMgnt = charIDToTypeID( "Mgnt" );
desc101.putDouble( idMgnt, 68.240000 );
var idYlw = charIDToTypeID( "Ylw " );
desc101.putDouble( idYlw, 65.880000 );
var idBlck = charIDToTypeID( "Blck" );
desc101.putDouble( idBlck, 88.630000 );
var idCMYC = charIDToTypeID( "CMYC" );
desc100.putObject( idClr, idCMYC, desc101 );
executeAction( idStrk, desc100, DialogModes.NO );
/////////////////////// add white ////////////////////////////////////
docRef.resizeCanvas ((Number(selectedWeld)/2) + activeDocument.width,activeDocument.height, AnchorPosition.MIDDLERIGHT);
docRef.resizeCanvas ((Number(selectedWeld)/2) + activeDocument.width, activeDocument.height, AnchorPosition.MIDDLELEFT);
docRef.resizeCanvas (activeDocument.width, (Number(selectedWeld)/2) + activeDocument.height, AnchorPosition.TOPCENTER);
docRef.resizeCanvas (activeDocument.width, (Number(selectedWeld)/2) + activeDocument.height, AnchorPosition.BOTTOMCENTER);
//////////////////////// stroke ////////////////////////////////////
activeDocument.selection.selectAll();
var idStrk = charIDToTypeID( "Strk" );
var desc100 = new ActionDescriptor();
var idWdth = charIDToTypeID( "Wdth" );
desc100.putInteger( idWdth, 1 );
var idLctn = charIDToTypeID( "Lctn" );
var idStrL = charIDToTypeID( "StrL" );
var idCntr = charIDToTypeID( "Cntr" );
desc100.putEnumerated( idLctn, idStrL, idCntr );
var idOpct = charIDToTypeID( "Opct" );
var idPrc = charIDToTypeID( "#Prc" );
desc100.putUnitDouble( idOpct, idPrc, 100.000000 );
var idMd = charIDToTypeID( "Md " );
var idBlnM = charIDToTypeID( "BlnM" );
var idNrml = charIDToTypeID( "Nrml" );
desc100.putEnumerated( idMd, idBlnM, idNrml );
var idClr = charIDToTypeID( "Clr " );
var desc101 = new ActionDescriptor();
var idCyn = charIDToTypeID( "Cyn " );
desc101.putDouble( idCyn, 75.290000 );
var idMgnt = charIDToTypeID( "Mgnt" );
desc101.putDouble( idMgnt, 68.240000 );
var idYlw = charIDToTypeID( "Ylw " );
desc101.putDouble( idYlw, 65.880000 );
var idBlck = charIDToTypeID( "Blck" );
desc101.putDouble( idBlck, 88.630000 );
var idCMYC = charIDToTypeID( "CMYC" );
desc100.putObject( idClr, idCMYC, desc101 );
executeAction( idStrk, desc100, DialogModes.NO );
if (eyeletTop > 0) {
var NEW_LAYER_NAME = "Layer 1";
var createNewLayer = function() {
try {
if (app.documents.length) {
var doc = activeDocument;
var layers = doc.artLayers;
var newLayer = layers.add();
if(NEW_LAYER_NAME) {
newLayer.name = NEW_LAYER_NAME;
}
doc.activeLayer = newLayer;
}
} catch (e) {
}
}
createNewLayer();
app.preferences.rulerUnits = Units.CM;
app.preferences.typeUnits = TypeUnits.MM;
var sw = activeDocument.resolution / 10 ;
var sh = activeDocument.resolution / 1.5 ;
var x = 0;
var y = 0;
app.activeDocument.selection.select([ [x,y], [x,y+sh], [x+sw,y+sh], [x+sw,y] ]);
fillColor = new CMYKColor();
fillColor.cyan = 100;
fillColor.magenta = 100;
fillColor.yellow = 100;
fillColor.black = 100;
app.activeDocument.selection.fill(fillColor);
app.activeDocument.selection.fill(fillColor);
app.activeDocument.selection.fill(fillColor);
app.activeDocument.selection.fill(fillColor);
app.activeDocument.selection.fill(fillColor);
app.activeDocument.selection.deselect();
app.preferences.rulerUnits = strtRulerUnits;
app.preferences.typeUnits = strtTypeUnits
var stepsHorizontal = Math.round((activeDocument.width-selectedWeld) / eyeletTop); // number of passes
var shiftWidth = (activeDocument.width-selectedWeld) / stepsHorizontal; // shift width
var szerokosc = activeDocument.width-selectedWeld;
var wysokosc = activeDocument.height-selectedWeld;
var LB = activeDocument.activeLayer.bounds;
activeDocument.activeLayer.translate(firstShift-LB[0].value,0-LB[1].value);
var x;
for (x=0; x<stepsHorizontal; x++) {
var layerRef = activeDocument.artLayers.getByName("Layer 1");
var newLayer = layerRef.duplicate();
docRef.activeLayer = newLayer;
var licznik = 1;
activeDocument.activeLayer = activeDocument.artLayers.getByName("Layer " + licznik++);
var LB = activeDocument.activeLayer.bounds;
activeDocument.activeLayer.translate(shiftWidth-LB[1].value,0-LB[1].value);
}
var docRef = app.activeDocument;
docRef.flatten();
}else {
}
The most important part is here:
var stepsHorizontal = Math.round((activeDocument.width-selectedWeld) / eyeletTop); // number of passes
var shiftWidth = (activeDocument.width-selectedWeld) / stepsHorizontal; // shift width
Instead of this code
var x;
for (x=0; x<stepsHorizontal; x++) {
var layerRef = activeDocument.artLayers.getByName("Layer 1");
var newLayer = layerRef.duplicate();
docRef.activeLayer = newLayer;
var licznik = 1;
activeDocument.activeLayer = activeDocument.artLayers.getByName("Layer " + licznik++);
var LB = activeDocument.activeLayer.bounds;
activeDocument.activeLayer.translate(shiftWidth-LB[1].value,0-LB[1].value);
}
use
...var x;
for (x=0; x<stepsHorizontal; x++) {
var layerRef = acti
Copy link to clipboard
Copied
I do not understand the purpose of the script.
The script is written rather stupidly. (I apologize if I offended someone ))).
Strongly without understanding, I can offer
var stepsHorizontal = 1 - Math.ceil((activeDocument.width.value-selectedWeld) / eyeletTop);
Copy link to clipboard
Copied
I wrote it in my native language and corrected it using Google translator, which is why it's hard to understand. Im sorry. Thank you for your help, but I do not understand why you added 1 - to math.ceil? By replacing it like you have, I have only one marker on the left;)
Using the script on the file 500x100 100DPI and 500x100 20DPI you can see what's going on (the last marker on the right is shifted at 20DPI). Of course, this size is just an example because I use this part of the script in different document dimensions.
Copy link to clipboard
Copied
Your script gives me one marker on the file
w = 500, h = 100, rez = 100px/inch.
and two markers on the file
w = 500, h = 100, rez = 20px/inch (or much less).
So I thought that you only want one marker.
P.S.I don't understand a damn thing in English either. )
Copy link to clipboard
Copied
500x100 100DPI:
500X100 20DPI:
It should look like that, checked on cs6 and cc.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
haha now I know why you did not understand it;)) it works with 500x100 CM not PX;))) I'm sorry, it's obvious for me that I work on CM and that's why I did not add it. ;))
Copy link to clipboard
Copied
Instead of this code
var x;
for (x=0; x<stepsHorizontal; x++) {
var layerRef = activeDocument.artLayers.getByName("Layer 1");
var newLayer = layerRef.duplicate();
docRef.activeLayer = newLayer;
var licznik = 1;
activeDocument.activeLayer = activeDocument.artLayers.getByName("Layer " + licznik++);
var LB = activeDocument.activeLayer.bounds;
activeDocument.activeLayer.translate(shiftWidth-LB[1].value,0-LB[1].value);
}
use
var x;
for (x=0; x<stepsHorizontal; x++) {
var layerRef = activeDocument.artLayers.getByName("Layer 1");
var newLayer = layerRef.duplicate();
docRef.activeLayer = newLayer;
var LB = activeDocument.activeLayer.bounds;
activeDocument.activeLayer.translate(shiftWidth*(x+1) ,0);
}
In this case, the error is not more than 1px.
REM: At 20dpi 1px = 0.127cm
=======================
UPD.
You can try to use vector shapes. Then everything will be fine.
Copy link to clipboard
Copied
Perfectly! Thank you. Could you additionally tell me how to move the tags vertically in this way? From the upper left corner to the lower left;) With the horizontal shift at the bottom I handled it myself;)
Copy link to clipboard
Copied
Do you want me to write you a new script? :)
You have to do it yourself.
The idea is not to move each new layer to the distance (step_width / step_height),
but to move the layer from the starting point to the distance step_width * (step + 1);
P.S. String in my code
var LB = activeDocument.activeLayer.bounds;
nor used (extra)
Copy link to clipboard
Copied
got it
var x;
for (x=0; x<stepsHorizontal; x++) {
var layerRef = activeDocument.artLayers.getByName("Layer 1");
var newLayer = layerRef.duplicate();
docRef.activeLayer = newLayer;
var LB = activeDocument.activeLayer.bounds;
activeDocument.activeLayer.translate(0 ,shiftWidth*(x+1));
}
Thank you again, you've helped me a lot )