Copy link to clipboard
Copied
I created a guide layout but I need it in the visible form of a path or stroke, how to convert it, thanks.
Try this script. It will draw a rectangle shape around the guide. Change the line width to what you want. It will center the shape on the guide.
#target photoshop
var lineWidth = 6
app.preferences.rulerUnits = Units.PIXELS;
var doc = activeDocument
var g = doc.guides
for(var i=0;i<g.length;i++){
var loc = g[i].coordinate.value
if(g[i].direction == 'Direction.HORIZONTAL'){
makeLine (loc-lineWidth/2, 0, loc+lineWidth/2, doc.width)
}
else{
makeLine (
...
This version of the script will allow you to use the color picker to set the line color. It will use the foreground color, if you want to just set the foreground color before hand and not use the picker, set the variable userColor to false.
#target photoshop
var lineWidth = 6
var userColor = true;
if(userColor){
app.showColorPicker()
}
var cRed = foregroundColor.rgb.red;
var cGreen = foregroundColor.rgb.green;
var cBlue = foregroundColor.rgb.blue;
app.preferences.rulerUnits = Units.P
...
Here's a script that will break all the vertical lines at the gutters.
#target photoshop
var lineWidth = 6
var userColor = false;
if(userColor){
app.showColorPicker()
}
var cRed = foregroundColor.rgb.red;
var cGreen = foregroundColor.rgb.green;
var cBlue = foregroundColor.rgb.blue;
app.preferences.rulerUnits = Units.PIXELS;
var doc = activeDocument
var g = doc.guides
var vertG = []
var horG = []
var coord = new Array();
for (i=0;i<g.length;i++){
if(g[i].direction == 'Direction
...
Copy link to clipboard
Copied
I am a little greedy, can the different direction lines be grouped in different folders in order to batch organize?
Copy link to clipboard
Copied
Yea, they can.
Copy link to clipboard
Copied
This will put the lines in two groups.
#target photoshop
var lineWidth = 6
var userColor = false;
if(userColor){
app.showColorPicker()
}
var cRed = foregroundColor.rgb.red;
var cGreen = foregroundColor.rgb.green;
var cBlue = foregroundColor.rgb.blue;
app.preferences.rulerUnits = Units.PIXELS;
var doc = activeDocument
var g = doc.guides
var vertG = []
var horG = []
var coord = new Array();
for (i=0;i<g.length;i++){
if(g[i].direction == 'Direction.HORIZONTAL'){horG.push (g[i].coordinate.value)}
else{vertG.push (g[i].coordinate.value)}
};
horG.sort (function(a, b){return a - b});
var minV=horG[1]-horG[0];
for(i=0;i<horG.length-1;i++){
var newV = horG[i+1]-horG[i];
minV = Math.min(newV,minV)
}
makeGroup ('Horizontal Lines')
doc.activeLayer.name = 'Horizontal Lines'
for(var i=0;i<horG.length+1;i++){// make lines for hor guides full doc width
try{
makeLine (horG[i]-lineWidth/2, 0, horG[i]+lineWidth/2, doc.width)
}
catch(e){};
var cA = [horG[i],horG[i+1]];
if(horG[i+1]-horG[i] != minV && horG[i+1] >-1){
coord.push (cA)
}
}
doc.activeLayer = doc.layers[doc.layers.length-1];
makeGroup ('Vertical Lines');
doc.activeLayer.name = 'Vertical Lines'
for(var i=0;i<vertG.length;i++){
for(var j=0;j<coord.length;j++){
makeLine (coord[j][0], vertG[i]-lineWidth/2, coord[j][1], vertG[i]+lineWidth/2)
}
}
function makeLine(topS, leftS, bottomS, rightS ){
var idMk = charIDToTypeID( "Mk " );
var desc38 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref3 = new ActionReference();
var idcontentLayer = stringIDToTypeID( "contentLayer" );
ref3.putClass( idcontentLayer );
desc38.putReference( idnull, ref3 );
var idUsng = charIDToTypeID( "Usng" );
var desc39 = new ActionDescriptor();
var idType = charIDToTypeID( "Type" );
var desc40 = new ActionDescriptor();
var idClr = charIDToTypeID( "Clr " );
var desc41 = new ActionDescriptor();
var idRd = charIDToTypeID( "Rd " );
desc41.putDouble( idRd, cRed );
var idGrn = charIDToTypeID( "Grn " );
desc41.putDouble( idGrn, cGreen );
var idBl = charIDToTypeID( "Bl " );
desc41.putDouble( idBl, cBlue );
var idRGBC = charIDToTypeID( "RGBC" );
desc40.putObject( idClr, idRGBC, desc41 );
var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
desc39.putObject( idType, idsolidColorLayer, desc40 );
var idShp = charIDToTypeID( "Shp " );
var desc42 = new ActionDescriptor();
var idunitValueQuadVersion = stringIDToTypeID( "unitValueQuadVersion" );
desc42.putInteger( idunitValueQuadVersion, 1 );
var idTop = charIDToTypeID( "Top " );
var idPxl = charIDToTypeID( "#Pxl" );
desc42.putUnitDouble( idTop, idPxl,topS);
var idLeft = charIDToTypeID( "Left" );
var idPxl = charIDToTypeID( "#Pxl" );
desc42.putUnitDouble( idLeft, idPxl, leftS );
var idBtom = charIDToTypeID( "Btom" );
var idPxl = charIDToTypeID( "#Pxl" );
desc42.putUnitDouble( idBtom, idPxl, bottomS );
var idRght = charIDToTypeID( "Rght" );
var idPxl = charIDToTypeID( "#Pxl" );
desc42.putUnitDouble( idRght, idPxl, rightS );
var idtopRight = stringIDToTypeID( "topRight" );
var idPxl = charIDToTypeID( "#Pxl" );
desc42.putUnitDouble( idtopRight, idPxl, 0.000000 );
var idtopLeft = stringIDToTypeID( "topLeft" );
var idPxl = charIDToTypeID( "#Pxl" );
desc42.putUnitDouble( idtopLeft, idPxl, 0.000000 );
var idbottomLeft = stringIDToTypeID( "bottomLeft" );
var idPxl = charIDToTypeID( "#Pxl" );
desc42.putUnitDouble( idbottomLeft, idPxl, 0.000000 );
var idbottomRight = stringIDToTypeID( "bottomRight" );
var idPxl = charIDToTypeID( "#Pxl" );
desc42.putUnitDouble( idbottomRight, idPxl, 0.000000 );
var idRctn = charIDToTypeID( "Rctn" );
desc39.putObject( idShp, idRctn, desc42 );
var idstrokeStyle = stringIDToTypeID( "strokeStyle" );
var desc43 = new ActionDescriptor();
var idstrokeStyleVersion = stringIDToTypeID( "strokeStyleVersion" );
desc43.putInteger( idstrokeStyleVersion, 2 );
var idstrokeEnabled = stringIDToTypeID( "strokeEnabled" );
desc43.putBoolean( idstrokeEnabled, false );
var idfillEnabled = stringIDToTypeID( "fillEnabled" );
desc43.putBoolean( idfillEnabled, true );
var idstrokeStyleLineWidth = stringIDToTypeID( "strokeStyleLineWidth" );
var idPxl = charIDToTypeID( "#Pxl" );
desc43.putUnitDouble( idstrokeStyleLineWidth, idPxl, 1.000000 );
var idstrokeStyleLineDashOffset = stringIDToTypeID( "strokeStyleLineDashOffset" );
var idPnt = charIDToTypeID( "#Pnt" );
desc43.putUnitDouble( idstrokeStyleLineDashOffset, idPnt, 0.000000 );
var idstrokeStyleMiterLimit = stringIDToTypeID( "strokeStyleMiterLimit" );
desc43.putDouble( idstrokeStyleMiterLimit, 100.000000 );
var idstrokeStyleLineCapType = stringIDToTypeID( "strokeStyleLineCapType" );
var idstrokeStyleLineCapType = stringIDToTypeID( "strokeStyleLineCapType" );
var idstrokeStyleButtCap = stringIDToTypeID( "strokeStyleButtCap" );
desc43.putEnumerated( idstrokeStyleLineCapType, idstrokeStyleLineCapType, idstrokeStyleButtCap );
var idstrokeStyleLineJoinType = stringIDToTypeID( "strokeStyleLineJoinType" );
var idstrokeStyleLineJoinType = stringIDToTypeID( "strokeStyleLineJoinType" );
var idstrokeStyleMiterJoin = stringIDToTypeID( "strokeStyleMiterJoin" );
desc43.putEnumerated( idstrokeStyleLineJoinType, idstrokeStyleLineJoinType, idstrokeStyleMiterJoin );
var idstrokeStyleLineAlignment = stringIDToTypeID( "strokeStyleLineAlignment" );
var idstrokeStyleLineAlignment = stringIDToTypeID( "strokeStyleLineAlignment" );
var idstrokeStyleAlignCenter = stringIDToTypeID( "strokeStyleAlignCenter" );
desc43.putEnumerated( idstrokeStyleLineAlignment, idstrokeStyleLineAlignment, idstrokeStyleAlignCenter );
var idstrokeStyleScaleLock = stringIDToTypeID( "strokeStyleScaleLock" );
desc43.putBoolean( idstrokeStyleScaleLock, false );
var idstrokeStyleStrokeAdjust = stringIDToTypeID( "strokeStyleStrokeAdjust" );
desc43.putBoolean( idstrokeStyleStrokeAdjust, false );
var idstrokeStyleLineDashSet = stringIDToTypeID( "strokeStyleLineDashSet" );
var list3 = new ActionList();
desc43.putList( idstrokeStyleLineDashSet, list3 );
var idstrokeStyleBlendMode = stringIDToTypeID( "strokeStyleBlendMode" );
var idBlnM = charIDToTypeID( "BlnM" );
var idNrml = charIDToTypeID( "Nrml" );
desc43.putEnumerated( idstrokeStyleBlendMode, idBlnM, idNrml );
var idstrokeStyleOpacity = stringIDToTypeID( "strokeStyleOpacity" );
var idPrc = charIDToTypeID( "#Prc" );
desc43.putUnitDouble( idstrokeStyleOpacity, idPrc, 100.000000 );
var idstrokeStyleContent = stringIDToTypeID( "strokeStyleContent" );
var desc44 = new ActionDescriptor();
var idClr = charIDToTypeID( "Clr " );
var desc45 = new ActionDescriptor();
var idRd = charIDToTypeID( "Rd " );
desc45.putDouble( idRd, cRed );
var idGrn = charIDToTypeID( "Grn " );
desc45.putDouble( idGrn, cGreen );
var idBl = charIDToTypeID( "Bl " );
desc45.putDouble( idBl, cBlue );
var idRGBC = charIDToTypeID( "RGBC" );
desc44.putObject( idClr, idRGBC, desc45 );
var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
desc43.putObject( idstrokeStyleContent, idsolidColorLayer, desc44 );
var idstrokeStyleResolution = stringIDToTypeID( "strokeStyleResolution" );
desc43.putDouble( idstrokeStyleResolution, 300.000000 );
var idstrokeStyle = stringIDToTypeID( "strokeStyle" );
desc39.putObject( idstrokeStyle, idstrokeStyle, desc43 );
var idcontentLayer = stringIDToTypeID( "contentLayer" );
desc38.putObject( idUsng, idcontentLayer, desc39 );
var idLyrI = charIDToTypeID( "LyrI" );
desc38.putInteger( idLyrI, 28 );
executeAction( idMk, desc38, DialogModes.NO );
}
function makeGroup(name){
var idMk = charIDToTypeID( "Mk " );
var desc6 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var idlayerSection = stringIDToTypeID( "layerSection" );
ref1.putClass( idlayerSection );
desc6.putReference( idnull, ref1 );
var idlayerSectionStart = stringIDToTypeID( "layerSectionStart" );
desc6.putInteger( idlayerSectionStart, 2 );
var idlayerSectionEnd = stringIDToTypeID( "layerSectionEnd" );
desc6.putInteger( idlayerSectionEnd, 3 );
var idNm = charIDToTypeID( "Nm " );
desc6.putString( idNm, name );
executeAction( idMk, desc6, DialogModes.NO );
}
Copy link to clipboard
Copied
Thank you, Chuck, BTW, if I have several letters and I want to fill in each of the letters in each blank that we previously made, how to implement it? thanks!
Copy link to clipboard
Copied
I'm not sure what you mean. Can you post an example?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
So how do you want to input the letters? The user type them in as separate layers, then a script center them, or a prompt where the letters are all typed in at once, and the script splits them up and puts them in each box? Would this be part of the above script, or a different script to add the letters?
Copy link to clipboard
Copied
I guess a different script would be much easier to organize, so I prefer a different one, I type my text in a textbox in a layer and the script separates my text into the letterbox and align them into the blank that we previously created, I guess maybe the workflow like this.
Copy link to clipboard
Copied
Ok, I'll see what I can do. Trying to figure out how to deal with the text height to center, as different letters have different characteristics, like descenders, lower case, upper case, etc. Can't seem to find how to get the baseline value of existing text.
Copy link to clipboard
Copied
So a couple of small deviations would be OK, as I am using the Chinese calligraphic fonts to align with, so it might be a little distinction. Thank you!
Copy link to clipboard
Copied
Did you accomplish this?
Copy link to clipboard
Copied
I think so.
Copy link to clipboard
Copied
Oh my lord, where it is?
Copy link to clipboard
Copied
I'm working on it. There is a lot to figure out.
Copy link to clipboard
Copied
When you type Chinese characters, do they write up and down rather than left to write? Need to know to find the vertical center of the entire string. I'm taking a prompt input such as WJjdhife and figuring out the vertical center of that line in relation to its baseline, so I can position each character vertically in the boxes. If any of the fonts write vertically, then that messes up my calculations.
Copy link to clipboard
Copied
Chinese typography always has different parts, the most common type is left to right two parts structure which you should write from left to right, other complicated ones would be three parts or more, but the general principle is to write from left to right, from top to bottom, and the gravity always at the bottom and right side, not too much away from English letters.
Copy link to clipboard
Copied
Well I'll see how it goes. With normal type. Make some adjustments if it doesn't work with Chinese.
Copy link to clipboard
Copied
I am volunteering to be the experimenter.
Copy link to clipboard
Copied
Well, let me work out the basics, and you can test it.
Copy link to clipboard
Copied
How long will it cost?
Copy link to clipboard
Copied
Can the text automatically fill in the next document or artboard when overflowing?
Copy link to clipboard
Copied
I will have to make changes to have the overflow work. Here is what I have for a single file.
#target photoshop
var doc = activeDocument
app.preferences.rulerUnits = Units.POINTS;
var docG = doc.guides
var gH = []
var gV = []
var squaresV = []
var defaultValue = '';
var str = prompt("Enter text to place in squares", defaultValue);
var exitLoop = false;
//alert(str.substr (45, 1)=='')
for (var i=0;i<docG.length;i++){
if(docG[i].direction == 'Direction.HORIZONTAL' && (docG[i].coordinate.value !=0 && docG[i].coordinate.value !=doc.height.value)){
gH.push(docG[i].coordinate.value)
}
else if(docG[i].coordinate !=0 && docG[i].coordinate.value !=doc.width.value){gV.push(docG[i].coordinate.value)}
}
gH.sort (function(a, b){return a - b});
gV.sort (function(a, b){return a - b});
var minV=gH[1]-gH[0];
for(var i=0;i<gH.length-1;i++){//get the gutter size - min dimension
var newV = gH[i+1]-gH[i];
minV = Math.min(minV,newV)
}
for(var i=0;i<gH.length-1;i++){//put the start and stop coordinates of the vertical distance for the spaces
if(gH[i+1]-gH[i] != minV){
squaresV.push([gH[i],gH[i+1]])
}
}
var textLay = doc.artLayers.add();//make a text layer and measure the text to get the center to baseline distance
textLay.kind = LayerKind.TEXT;
var textItemRef = textLay.textItem;
textItemRef.justification = Justification.CENTER;
textItemRef.contents = str
var textCaps = textLay.bounds
var textH = textCaps[1].value
var textB = textCaps[3].value
var textVertCenter = (textB+textH)/2
var textOffset = textItemRef.position[1].value-textVertCenter
textLay.remove();
var count = 0;
for(var i=0;i<squaresV.length;i++){
if(exitLoop){break;}
var tS = squaresV[i][0];
var bS = squaresV[i][1];
var tCenterV = (tS+bS)/2;
var tBase = tCenterV+textOffset;
for(var j=0;j<gV.length-1;j++){
if(str.substr (count, 1)==''){
exitLoop = true;
break;
}
var lS = gV[j];
var rS = gV[j+1];
var tCenterH = (lS+rS)/2
textLay = doc.artLayers.add();//make a text layer and measure the text to get the center to baseline distance
textLay.kind = LayerKind.TEXT;
var textItemRef = textLay.textItem;
textItemRef.justification = Justification.CENTER;
textItemRef.contents = str.substr (count, 1);
textItemRef.position = [tCenterH,tBase]
count++;
}
}
Copy link to clipboard
Copied
It stucked
Copy link to clipboard
Copied
1. If the text is too long, it will get stuck. 2. Each word is a separate text box. Can you write all the text in one text box? 3. The numbers should be more compact. 4. The text is written in the gutter when the line is changed. 5. The second insertion script does not start from the end of the last text, but starts over again
Copy link to clipboard
Copied
When I first posted the last script, I forgot to take out the text size, so now it should default to whatever text size you last used. The script will just put one letter in each box, as your previous example showed. I will have to make some modifications to have it overflow to another document. It would be best to make one document, then duplicate it, and have however many documents you need to fill all the boxes.