Here is a simple sample to make color list in InDesign.
It is very simple, because, there are no left-right page handling, no color values for cyan, magenta, yellow and black, no page numbers, no comments, and no drawing the border of the color-box.
And I don't have much time to reply any question. Please try it on your own.
Here is the code:
main();
function main() {
if (app.documents.length == 0) {
var myDocument = app.documents.add();
basicSetup(myDocument);
myDocument.textFrames.item(0).remove();
makeSwatch(myDocument);
}
return 0;
}
function basicSetup(myDocument) {
myDocSetup(myDocument);
myMasterSpreads(myDocument);
}
function myDocSetup(myDocument) {
with (myDocument.documentPreferences) {
pageHeight = "29.8cm";
pageWidth = "21.6cm";
pageOrientation = PageOrientation.portrait;
facingPages == true;
documentBleedUniformSize = true;
documentBleedTopOffset = "3p";
documentSlugUniformSize = true;
slugTopOffset = "5p";
}
with (myDocument.pasteboardPreferences) {
minimumSpaceAboveAndBelow = "12p";
}
with (myDocument.viewPreferences) {
rulerOrigin = RulerOrigin.pageOrigin;
horizontalMeasurementUnits = MeasurementUnits.points;
verticalMeasurementUnits = MeasurementUnits.points;
}
}
function myMasterSpreads(myDocument) {
var FirstChapPage = "主版面";
var PageNoHeadings = "無書眉主版面";
var PageNumberHeadings = "頁碼主版面";
var nMSpA = myDocument.masterSpreads.item("A-主版");
var RenameA = false;
try {
var myName = nMSpA.name;
}
catch (myError) {
nMSpA = myDocument.masterSpreads.add();
}
with (nMSpA) {
baseName = FirstChapPage;
namePrefix = "A";
textFrames.item(1).remove();
textFrames.item(0).remove();
with (pages.item(0)) {
with (marginPreferences) {
bottom = "2.4cm"
left = "2.3cm"
right = "1.8cm"
top = "2.4cm"
}
}
with (pages.item(1)) {
with (marginPreferences) {
bottom = "2.4cm"
left = "2.3cm"
right = "1.8cm"
top = "2.4cm"
}
}
}
}
function makeSwatch(myDocument) {
var cc = 0;
var mm = 0;
var yy = 0;
var kk = 0;
var leftside = true;
var curPage;
var uvPageWidth = new UnitValue("21.6cm").as("pt");
var uvLeft = new UnitValue("2.3cm").as("pt");
var uvRight = new UnitValue("1.8cm").as("pt");
var uvYoff = new UnitValue("8.0cm").as("pt");
var uvYoff2 = new UnitValue("3.5cm").as("pt");
var uvAdvance = new UnitValue("1.5cm").as("pt");
var uvSize = new UnitValue("1.0cm").as("pt");
var uvXoff = uvLeft;
var Y1 = 0;
var X1 = 0;
var Y2 = 0;
var X2 = 0;
for (kk = 0; kk <= 100; kk += 10) {
for (yy = 0; yy <= 100; yy += 10) {
curPage = app.activeWindow.activePage;
Y1 = uvYoff2;
X1 = uvXoff;
Y2 = Y1 + uvSize;
X2 = X1 + uvSize;
var colStrY = addColor(0, 0, yy, 0, myDocument);
var myBoxY = curPage.rectangles.add({ geometricBounds: [Y1, X1, Y2, X2], fillColor: colStrY });
Y1 = uvYoff2;
X1 = uvXoff + uvAdvance;
Y2 = Y1 + uvSize;
X2 = X1 + uvSize;
var colStrK = addColor(0, 0, 0, kk, myDocument);
var myBoxK = curPage.rectangles.add({ geometricBounds: [Y1, X1, Y2, X2], fillColor: colStrK });
for (mm = 0; mm <= 100; mm += 10) {
for (cc = 0; cc <= 100; cc += 10) {
Y1 = uvYoff + (mm / 10) * uvAdvance;
X1 = uvXoff + (cc / 10) * uvAdvance;
Y2 = Y1 + uvSize;
X2 = X1 + uvSize;
var colStr = addColor(100 - cc, mm, yy, kk, myDocument);
var myBox = curPage.rectangles.add({ geometricBounds: [Y1, X1, Y2, X2], fillColor: colStr });
} // cc
} // mm
if (cc + mm + yy + kk >= 420)
return;
addPage(myDocument);
leftside = !leftside;
if (leftside)
uvXoff = uvLeft + uvPageWidth;
else
uvXoff = uvRight;
} // yy
} // kk
}
function addColor(cc, mm, yy, kk, myDocument) {
var cName = "z" + cc.toString() + "=" + mm.toString() + "=" + yy.toString() + "=" + kk.toString();
var myColor = myDocument.colors.item(cName);
try {
var myName = myColor.name;
}
catch (myError) {
myColor = myDocument.colors.add({ name: cName, model: ColorModel.process, colorValue: [cc, mm, yy, kk] });
}
return myColor;
}
function addPage(myDocument) {
myDocument.pages.add();
}
Note:
- The code is developed using the Traditional Chinese version of InDesign.
- If you use any other language version, please replace the names of spreads with proper names.
- Please handle the generated InDesign document with care: Don't click on the "Swatch" from the menu or tool bar. There are 14,641 swatches added to the document by the code! If you click on the "Swatch", InDesign would hang just in front of you.
- To run this code is on your own risk!
You may use the code. I don't keep any copyright with me about this code.
Good Luck!
Good Luck!
Comments