• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
2

scripting

Community Beginner ,
Apr 30, 2024 Apr 30, 2024

Copy link to clipboard

Copied

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

 

 

TOPICS
How-to , Performance , Scripting

Views

371

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Apr 30, 2024 Apr 30, 2024

Copy link to clipboard

Copied

I am sorry. For the life of me, I can't imagine how this ChatGPT code is supposed to lead to the result shown.

But the following revised version at least shows a result.

 

 

// 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(-88, 100, 263, 100);
    //rect.fillColor = doc.swatches["CMYK Rot"].color;  // German standard red color for my own test
    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();
    //pattern.moveToBeginning(group);
    textFrame.selected = true;
    textFrame.createOutline();
    app.executeMenuCommand("ungroup");
    app.executeMenuCommand("compoundPath");
    //textFrame.moveToBeginning(group);
    pattern.selected = true;
    app.executeMenuCommand("makeMask");
    //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 flag pattern
    var pattern = createFlagPattern(doc);

    // Create text
    var textFrame = createText(doc, "FLORIDA", 100, -100, 72);

    // Apply clipping mask
    applyClippingMask(doc, textFrame, pattern);
}

// Run the script
main();

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 30, 2024 Apr 30, 2024

Copy link to clipboard

Copied

Demo:

var doc = app.activeDocument;

// create flag
var flag = createFlag();

// create text
var index = createText(
    "FLORIDA", doc.width / 2, -doc.height / 2, 72, "Myriad-Bold");
var index = index.createOutline();
var repeats = doc.groupItems.add();
repeat(0.5, 0);
repeat(0.75, 0.5);
repeat(0.875, 0.75);
repeat(-0.5, -0);
repeat(-0.75, -0.5);
repeat(-0.875, -0.75);

// cleate clipping set
var compoundPath = doc.compoundPathItems.add();
index.moveToEnd(compoundPath);
repeats.moveToEnd(compoundPath);
compoundPath.selected = true;
flag.selected = true;
app.executeMenuCommand("makeMask");

function createFlag() {
    var w = doc.width / 4, h = doc.height / 2, y = - doc.height / 2 + h / 2;
    function createRect(x, red, blue) {
        var rect = doc.pathItems.rectangle(y, x, w, h);
        var color = new RGBColor;
        color.red = red;
        color.blue = blue;
        rect.fillColor = color;
        return rect;
    }
    var flag = doc.groupItems.add();
    createRect(doc.width / 2 - w, 255, 0).moveToEnd(flag);
    createRect(doc.width / 2, 0, 255).moveToEnd(flag);
    return flag;
}

function createText(contents, x, y, fontSize, textFont) {
    var textFrame = doc.textFrames.pointText( [x, y] );
    textFrame.contents = contents;
    textFrame.textRange.size = fontSize;
    textFrame.textRange.textFont = textFonts[textFont];
    textFrame.textRange.justification = Justification.CENTER;
    return textFrame;
}

function repeat(value1, value2) {
    var members = [];
    for (var i = index.pageItems.length - 1; i > -1; i--) {
        var duple = index.pageItems[i].duplicate(index, ElementPlacement.PLACEAFTER);
        members.push(duple);
    }
    for (var i = 0; i < members.length; i++) {
        members[i].translate(0, members[i].height * value1);
        var rect = doc.pathItems.rectangle(
            index.top, index.left, index.width, index.height);
        rect.translate(0, rect.height * value2);
        rect.selected = members[i].selected = true;
        app.executeMenuCommand("group");
        app.executeMenuCommand("Live Pathfinder Subtract");
        app.executeMenuCommand("expandStyle");
        app.executeMenuCommand("ungroup");
        rect.remove();
        for (var j = app.selection.length - 1; j > -1; j--) {
            app.selection[j].moveToEnd(repeats);
        }
        app.selection = null;
    }
}

femkeblanco_0-1714521500776.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 01, 2024 May 01, 2024

Copy link to clipboard

Copied

thanks a lot 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 01, 2024 May 01, 2024

Copy link to clipboard

Copied

thanks a lot buddy

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 30, 2024 Apr 30, 2024

Copy link to clipboard

Copied

Here is a screenshot of the result (note: text is no longer live text):

pixxxelschubser_0-1714507583937.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 30, 2024 Apr 30, 2024

Copy link to clipboard

Copied

Some people would try to be a bit more adamant when it comes to tackle a task assisted by ChatGPT. Did you provide a detailed requirements specification to the machine (something that a human creator would need as well)?

 

In case you already tried that, what did ChatGPT told you about the reasons why the script provided so far does not work as desired? It's pretty obvious why it does not meet your needs as per your screenshot and the code you provided. But if you think that you may get something pleasant with the practised hand of ChatGPT, I'd assume that you have to talk to it in depth, providing all necessary details in order to get your goal.

 

Apart from that, I think that a nested graphic style may be an alternative appropriate approach to get what you want. It could be a bit complicated, but it may work.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 01, 2024 May 01, 2024

Copy link to clipboard

Copied

thanks for your comment. i am still not a coding expert.

so yes i gave it a try with chat gpt but thought it would be more efficient here.

so please no critism. thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 01, 2024 May 01, 2024

Copy link to clipboard

Copied

LATEST

No criticism intended. And you are probably right that it may still be more efficient to ask in this forum.

 

I just wanted to indicate that you will have to provide uber-precise instructions to so-called intelligent devices like ChatGPT in order to get some well-oiled scripting approaches.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines