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.
(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);
}