mirror of
https://github.com/github/awesome-copilot.git
synced 2026-04-30 12:15:56 +00:00
new skill adobe-illustrator-scripting (#1448)
* new skill adobe-illustrator-scripting * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
// batch-export-png.jsx
|
||||
// Exports every open Illustrator document as a PNG24 file to a chosen folder.
|
||||
// Usage: Run from File > Scripts > Other Scripts in Adobe Illustrator.
|
||||
|
||||
#target illustrator
|
||||
|
||||
(function () {
|
||||
if (app.documents.length === 0) {
|
||||
alert("No documents are open.");
|
||||
return;
|
||||
}
|
||||
|
||||
var outputFolder = Folder.selectDialog("Select output folder for PNG export");
|
||||
if (!outputFolder) return;
|
||||
|
||||
var savedInteraction = app.userInteractionLevel;
|
||||
app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
|
||||
|
||||
try {
|
||||
for (var i = app.documents.length - 1; i >= 0; i--) {
|
||||
var doc = app.documents[i];
|
||||
var fileName = doc.name.replace(/\.[^.]+$/, "");
|
||||
var destFile = new File(outputFolder + "/" + fileName + ".png");
|
||||
|
||||
var pngOpts = new ExportOptionsPNG24();
|
||||
pngOpts.transparency = true;
|
||||
pngOpts.artBoardClipping = true;
|
||||
pngOpts.horizontalScale = 100;
|
||||
pngOpts.verticalScale = 100;
|
||||
|
||||
doc.exportFile(destFile, ExportType.PNG24, pngOpts);
|
||||
}
|
||||
alert("Exported " + app.documents.length + " file(s) to:\n" + outputFolder.fsName);
|
||||
} catch (e) {
|
||||
alert("Export error: " + e.message);
|
||||
} finally {
|
||||
app.userInteractionLevel = savedInteraction;
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,38 @@
|
||||
// create-color-grid.jsx
|
||||
// Creates a grid of colored rectangles to demonstrate path creation,
|
||||
// color manipulation, and layer organization in Illustrator scripting.
|
||||
// Usage: Run from File > Scripts > Other Scripts in Adobe Illustrator.
|
||||
|
||||
#target illustrator
|
||||
|
||||
(function () {
|
||||
var doc = app.documents.add();
|
||||
var layer = doc.layers.add();
|
||||
layer.name = "Color Grid";
|
||||
|
||||
var columns = 5;
|
||||
var rows = 4;
|
||||
var cellSize = 72; // 1 inch
|
||||
var gap = 10;
|
||||
var startX = 72;
|
||||
var startY = doc.height - 72;
|
||||
|
||||
for (var row = 0; row < rows; row++) {
|
||||
for (var col = 0; col < columns; col++) {
|
||||
var x = startX + col * (cellSize + gap);
|
||||
var y = startY - row * (cellSize + gap);
|
||||
|
||||
var rect = layer.pathItems.rectangle(y, x, cellSize, cellSize);
|
||||
|
||||
var color = new RGBColor();
|
||||
color.red = Math.round((col / (columns - 1)) * 255);
|
||||
color.green = Math.round((row / (rows - 1)) * 255);
|
||||
color.blue = Math.round(128 + Math.random() * 127);
|
||||
|
||||
rect.fillColor = color;
|
||||
rect.stroked = false;
|
||||
}
|
||||
}
|
||||
|
||||
app.redraw();
|
||||
})();
|
||||
@@ -0,0 +1,32 @@
|
||||
// find-replace-text.jsx
|
||||
// Finds and replaces text across all text frames in the active document.
|
||||
// Usage: Run from File > Scripts > Other Scripts in Adobe Illustrator.
|
||||
|
||||
#target illustrator
|
||||
|
||||
(function () {
|
||||
if (app.documents.length === 0) {
|
||||
alert("No document is open.");
|
||||
return;
|
||||
}
|
||||
|
||||
var doc = app.activeDocument;
|
||||
|
||||
var findStr = prompt("Find text:", "");
|
||||
if (findStr === null || findStr === "") return;
|
||||
|
||||
var replaceStr = prompt("Replace with:", "");
|
||||
if (replaceStr === null) return;
|
||||
|
||||
var count = 0;
|
||||
for (var i = 0; i < doc.textFrames.length; i++) {
|
||||
var tf = doc.textFrames[i];
|
||||
var original = tf.contents;
|
||||
if (original.indexOf(findStr) !== -1) {
|
||||
tf.contents = original.split(findStr).join(replaceStr);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
alert("Replaced text in " + count + " text frame(s).");
|
||||
})();
|
||||
Reference in New Issue
Block a user