// Skrypt generujący tabelę kolorów z danymi technicznymi
// Wymagania: Adobe InDesign CC lub nowsze
function main() {
if (app.documents.length == 0) {
alert("Proszę otworzyć dokument InDesign!");
return;
}
const doc = app.activeDocument;
const colors = collectUsedColors(doc);
if (colors.length === 0) {
alert("Brak użytych kolorów w dokumencie!");
return;
}
// Sortowanie kolorów alfabetycznie
colors.sort((a, b) => a.name.localeCompare(b.name));
// Tworzenie tabeli
const newPage = doc.pages.add();
createColorTable(newPage, colors);
// Opcjonalny zapis do PDF
if (confirm("Czy zapisać tabelę jako plik PDF?")) {
saveAsPDF(doc, colors);
}
}
// zbieranie użytych kolorów
function collectUsedColors(doc) {
const colors = [];
doc.allPageItems.everyItem().getElements().forEach(item => {
checkColor(item.fillColor, colors);
checkColor(item.strokeColor, colors);
});
return colors;
}
// sprawdza i dodaje kolor do listy
function checkColor(color, list) {
if (!color || color.name === "[None]") return;
const existing = list.find(c => c.id === color.id);
if (!existing) {
list.push({
id: color.id,
name: color.name,
type: color.colorType === ColorType.SPOT ? "Spot" : "Process",
model: getColorModel(color),
cmyk: color.cmyk,
rgb: color.rgb,
swatch: color
});
}
}
// określa model koloru
function getColorModel(color) {
if (color.model === ColorModel.CMYK) return "CMYK";
if (color.model === ColorModel.RGB) return "RGB";
if (color.model === ColorModel.GRAYSCALE) return "Grayscale";
return "Other";
}
// Tworzenie tabeli
function createColorTable(page, colors) {
const bounds = page.bounds;
const margin = 20;
const tableWidth = bounds[3] - bounds[1] - 2*margin;
const rowHeight = 20;
const table = page.textFrames.add({
geometricBounds: [
margin,
margin,
margin + (colors.length + 1)*rowHeight,
margin + tableWidth
]
}).tables.add();
table.columnCount = 5;
table.bodyRowCount = colors.length;
table.headerRowCount = 1;
// Ustawienie szerokości kolumn
table.columns[0].width = tableWidth * 0.3; // Nazwa
table.columns[1].width = tableWidth * 0.15; // Typ
!!!!!! table.columns[2].width = tableWidth * 0.25; // Model
table.columns[3].width = tableWidth * 0.15; // Wartości
table.columns[4].width = tableWidth * 0.15; // Próbka
// Nagłówek
const header = table.rows[0];
header.cells[0].contents = "Nazwa";
header.cells[1].contents = "Typ";
header.cells[2].contents = "Model";
header.cells[3].contents = "Wartości";
header.cells[4].contents = "Próbka";
header.fillColor = doc.colors.item("[Black]");
header.texts[0].fillColor = doc.colors.item("[Paper]");
header.texts[0].font = "Arial Bold";
// Wypełnianie danymi
colors.forEach((colorData, index) => {
const row = table.rows[index + 1];
row.cells[0].contents = colorData.name;
row.cells[1].contents = colorData.type;
row.cells[2].contents = colorData.model;
// Wartości kolorów
const values = colorData.model === "CMYK"
? `C${colorData.cmyk.c}% M${colorData.cmyk.m}% Y${colorData.cmyk.y}% K${colorData.cmyk.k}%`
: `R${colorData.rgb.r} G${colorData.rgb.g} B${colorData.rgb.b}`;
row.cells[3].contents = values;
// Próbka koloru
row.cells[4].fillColor = colorData.swatch;
row.cells[4].strokeColor = doc.colors.item("[Black]");
row.cells[4].strokeWeight = "0.5mm";
});
}
// Zapis do PDF
function saveAsPDF(doc, colors) {
const file = File.saveDialog("Zapisz tabelę jako PDF");
if (!file) return;
const exportPreset = app.pdfExportPresets.item("PDFX_1-a_2001");
doc.exportFile(ExportFormat.pdfType, file, true, exportPreset);
alert("Tabela została zapisana jako PDF!");
}
// Uruchomienie
try {
main();
} catch (e) {
alert("Błąd: " + e.message);
}
Jeśli potrzebujesz dodatkowych funkcji (np. kodów HEX, Pantone, lub innych modyfikacji) — powiedz, dostosuję skrypt! 😊