質問
scripting
- April 30, 2024
- 返信数 3.
- 920 ビュー
Hello community,
I would like to create a script for the attached graphic.
the goal is not to have to build everything manually but to be able to execute a script to determine the arrangement and the corresponding mask with the usa flag.
Later I just want to customise the city (e.g. Texas) and have the same design created. (Keyword scalability)
I have tried to create a script via chat gpt4 (see attachment) but it doesn't seem to work.
Can anyone help?
Thanks a lot.
Cheers Eran
#target illustrator
// Function to create text
function createText(doc, textContent, posX, posY, fontSize) {
var textFrame = doc.textFrames.add();
textFrame.contents = textContent;
textFrame.textRange.characterAttributes.size = fontSize;
textFrame.left = posX;
textFrame.top = posY;
return textFrame;
}
// Function to create flag pattern (simplified version)
function createFlagPattern(doc) {
var rect = doc.pathItems.rectangle(100, 100, 200, 100);
rect.fillColor = doc.swatches["Red"].color; // Assuming 'Red' is a predefined swatch
// Add more details like stripes and stars as per requirement
return rect;
}
// Function to apply clipping mask
function applyClippingMask(doc, textFrame, pattern) {
var group = doc.groupItems.add();
textFrame.moveToBeginning(group);
pattern.moveToBeginning(group);
group.clipped = true;
}
// Main function to execute
function main() {
if (app.documents.length == 0) {
alert("Please open a document and try again.");
return;
}
var doc = app.activeDocument;
// Create text
var textFrame = createText(doc, "FLORIDA", 100, -100, 72);
// Create flag pattern
var pattern = createFlagPattern(doc);
// Apply clipping mask
applyClippingMask(doc, textFrame, pattern);
}
// Run the script
main();
