Copy link to clipboard
Copied
Hi adobe community, hope you're doing great!
I know there might be scripts that does this around there but I need to add something specific. I would like a script that adds boxes (squares) filled with the swatch color in the swatches along with the name, BUT, i would like to have the feature to set it horizontal (square with name below) and vertical (square with name to the right side). Squares size 25px x 25px and names right side or below, normally the colors will be re-named in only 5 character (802 C for example), I mention it for the distance among them, or maybe they can have a 10px distance between them.
Last, I would like it to "search" for a specific position to be placed, please see attached picture, I would like to be able to set the colors wherever I need it. Beware! I need only spot colors, not [registration] or other colors only spot (or pantone idk the name). ALso I am attaching one I found there, It might helps.
Please, and thanks!
(1) About the prompt, the first and second values are the top and left coordinates of the horizontal group and the third and fourth values are the top and left coordinates of the vertical group.
(2) If you are asking for the option to choose either the horizontal group or the vertical group,
var w = 25, gap = 10, margin = 10, fontSize = 7.5;
var choice = confirm("Horizontal group? (YES for horizontal. NO for vertical.)");
var input = prompt("Enter top and left coordinates, separated by commas
...
Copy link to clipboard
Copied
var w = 25, gap = 10, margin = 10;
var input = prompt("Enter top1, left1, top2, left2, separated by commas.", "0, 70, 70, 0");
var input = input.split(",");
var top1 = -(Number(input[0]) + margin), left1 = Number(input[1]) + margin;
var top2 = -(Number(input[2]) + margin), left2 = Number(input[3]) + margin;
var black = new GrayColor();
black.gray = 100;
var doc = app.activeDocument;
var group1 = doc.groupItems.add();
var group2 = doc.groupItems.add();
for (var i = 0; i < doc.swatches.length; i++) {
if (doc.swatches[i].color.typename == "SpotColor") {
if (!(doc.swatches[i].name == "[Registration]")) {
var rect1 = doc.pathItems.rectangle(top1, left1, w, w);
rect1.strokeColor = black;
rect1.fillColor = doc.swatches[i].color;
rect1.moveToEnd(group1);
var text1 = doc.textFrames.pointText([left1 + w / 2, top1 - (w + gap)]);
text1.contents = doc.swatches[i].name;
text1.textRange.fillColor = black;
text1.textRange.size = 7.5;
text1.textRange.justification = Justification.CENTER;
text1.moveToEnd(group1);
left1 += (w + gap);
var rect2 = doc.pathItems.rectangle(top2, left2, w, w);
rect2.strokeColor = black;
rect2.fillColor = doc.swatches[i].color;
rect2.moveToEnd(group2);
var text2 = doc.textFrames.pointText([left2 + (w + gap), top2 - w / 2]);
text2.contents = doc.swatches[i].name;
text2.textRange.fillColor = black;
text2.textRange.size = 7.5;
text2.textRange.justification = Justification.LEFT;
text2.moveToEnd(group2);
top2 -= (w + gap);
}
}
}
var rect1 = doc.pathItems.rectangle(
- input[0], input[1], Math.abs((left1 - Number(input[1]))), margin * 2 + w * 2
);
rect1.strokeColor = black;
rect1.filled = false;
rect1.moveToEnd(group1);
var rect2 = doc.pathItems.rectangle(
- input[2], input[3], margin * 2 + w * 2, Math.abs(top2 + Number(input[2]))
);
rect2.strokeColor = black;
rect2.filled = false;
rect2.moveToEnd(group2);
Copy link to clipboard
Copied
let me try it bro!
Copy link to clipboard
Copied
I want to inform that user @femkeblanco got a really nice script! Pretty close of what I was looking for! I just was wondering if you my friend can help me editing a little bit the code, and explaining something?
1) What are the values of the prompt windows for? I try to catch it but i cant.
2) Can you help me put with a parameter in the script where I can decide which line up use, vertical or horizontal so the scripts creates what I need?
I will also appreciate other versions and ideas! thanks!
Copy link to clipboard
Copied
Cool. That works well. Here's a little addition to shorten PANTONE colour names:
text1.contents = doc.swatches[i].name.replace(/PANTONE\s(.+)$/, '$1');
text2.contents = doc.swatches[i].name.replace(/PANTONE\s(.+)$/, '$1');
Copy link to clipboard
Copied
Thanks a lot for the addition! Just if possible, somebody help me a bit with my last comment , that's my only doubt and revision request.
Copy link to clipboard
Copied
(1) About the prompt, the first and second values are the top and left coordinates of the horizontal group and the third and fourth values are the top and left coordinates of the vertical group.
(2) If you are asking for the option to choose either the horizontal group or the vertical group,
var w = 25, gap = 10, margin = 10, fontSize = 7.5;
var choice = confirm("Horizontal group? (YES for horizontal. NO for vertical.)");
var input = prompt("Enter top and left coordinates, separated by commas.", "0, 0");
var input = input.split(",");
var top1 = -(Number(input[0]) + margin), left1 = Number(input[1]) + margin;
var black = new GrayColor();
black.gray = 100;
var doc = app.activeDocument;
var group1 = doc.groupItems.add();
var group2 = doc.groupItems.add();
for (var i = 0; i < doc.swatches.length; i++) {
if (doc.swatches[i].color.typename == "SpotColor") {
if (!(doc.swatches[i].name == "[Registration]")) {
if (choice == true) { // horizontal group
var rect1 = doc.pathItems.rectangle(
top1, left1, w, w
);
rect1.strokeColor = black;
rect1.fillColor = doc.swatches[i].color;
rect1.moveToEnd(group1);
var text1 = doc.textFrames.pointText(
[left1 + w / 2, top1 - (w + gap)]
);
text1.contents = doc.swatches[i].name;
text1.textRange.fillColor = black;
text1.textRange.size = fontSize;
text1.textRange.justification = Justification.CENTER;
text1.moveToEnd(group1);
left1 += (w + gap);
} else { // vertical group
var rect2 = doc.pathItems.rectangle(
top1, left1, w, w
);
rect2.strokeColor = black;
rect2.fillColor = doc.swatches[i].color;
rect2.moveToEnd(group2);
var text2 = doc.textFrames.pointText(
[left1 + (w + gap), top1 - w / 2]
);
text2.contents = doc.swatches[i].name;
text2.textRange.fillColor = black;
text2.textRange.size = fontSize;
text2.textRange.justification = Justification.LEFT;
text2.moveToEnd(group2);
top1 -= (w + gap);
}
}
}
}
if (choice == true) { // horizontal group
var rect1 = doc.pathItems.rectangle(
- input[0], input[1],
Math.abs((left1 - Number(input[1]))), margin * 2 + w * 2
);
rect1.strokeColor = black;
rect1.filled = false;
rect1.moveToEnd(group1);
} else { // vertical group
var rect2 = doc.pathItems.rectangle(
- input[0], input[1], margin * 2 + w * 2,
Math.abs(top1 + Number(input[0]))
);
rect2.strokeColor = black;
rect2.filled = false;
rect2.moveToEnd(group2);
}
Copy link to clipboard
Copied
Thank you I appreciate it a lot! I'll try to modify it to set the coordinates manually and position manually as well (vertial and horizontal) without the promt, but for sure this answers the question and task!