Skip to content
The Chat Archive
claude-opus-4-20250514· Anthropic LMArena Human Preference 140K

#target illustrator function main() { // ScriptUI Dialog var dlg = new Window('dialog',…

  1. User

    #target illustrator

    function main() { // ScriptUI Dialog var dlg = new Window('dialog', 'Batch Icon Board Generator'); dlg.alignChildren = 'fill';

    // Title & Subtitle
    var titleGroup = dlg.add('panel', undefined, 'Title & Subtitle');
    titleGroup.orientation = 'column';
    titleGroup.alignChildren = 'left';
    titleGroup.margins = 10;
    titleGroup.add('statictext', undefined, 'Main Title:');
    var titleInput = titleGroup.add('edittext', undefined, 'TOOTH\nBRUSHING');
    titleInput.characters = 25;
    titleGroup.add('statictext', undefined, 'Subtitle:');
    var subtitleInput = titleGroup.add('edittext', undefined, '50 ICONS');
    subtitleInput.characters = 25;
    titleGroup.add('statictext', undefined, 'Title Font Size:');
    var fontSizeInput = titleGroup.add('edittext', undefined, '60');
    fontSizeInput.characters = 5;
    titleGroup.add('statictext', undefined, 'Subtitle Font Size:');
    var subFontSizeInput = titleGroup.add('edittext', undefined, '48');
    subFontSizeInput.characters = 5;
    
    // Color Picker Panel
    var colorGroup = dlg.add('panel', undefined, 'Block Color');
    colorGroup.orientation = 'row';
    colorGroup.alignChildren = 'left';
    colorGroup.margins = 10;
    var colorSample = colorGroup.add('panel', undefined, '');
    colorSample.preferredSize = [40, 20];
    colorSample.graphics.backgroundColor = colorSample.graphics.newBrush(colorSample.graphics.BrushType.SOLID_COLOR, [80/255,200/255,210/255,1]);
    var pickColorBtn = colorGroup.add('button', undefined, 'Pick Color');
    var pickedColor = [80,200,210]; // default
    
    pickColorBtn.onClick = function() {
        var c = $.colorPicker();
        if (c !== -1) {
            pickedColor = [
                (c >> 16) & 0xFF,
                (c >> 8) & 0xFF,
                c & 0xFF
            ];
            colorSample.graphics.backgroundColor = colorSample.graphics.newBrush(colorSample.graphics.BrushType.SOLID_COLOR, [pickedColor[0]/255, pickedColor[1]/255, pickedColor[2]/255, 1]);
        }
    }
    
    // Folder selection
    var folderGroup = dlg.add('panel', undefined, 'Folders');
    folderGroup.orientation = 'column';
    folderGroup.alignChildren = 'left';
    folderGroup.margins = 10;
    var inputFolderBtn = folderGroup.add('button', undefined, 'Select Input Folder');
    var inputFolderText = folderGroup.add('statictext', undefined, 'No folder selected', {truncate:'middle'});
    var outputFolderBtn = folderGroup.add('button', undefined, 'Select Output Folder');
    var outputFolderText = folderGroup.add('statictext', undefined, 'No folder selected', {truncate:'middle'});
    var inputFolder = null, outputFolder = null;
    
    inputFolderBtn.onClick = function() {
        inputFolder = Folder.selectDialog("Select folder with EPS files");
        if (inputFolder) inputFolderText.text = inputFolder.fsName;
    }
    outputFolderBtn.onClick = function() {
        outputFolder = Folder.selectDialog("Select output folder");
        if (outputFolder) outputFolderText.text = outputFolder.fsName;
    }
    
    // Buttons
    var btnGroup = dlg.add('group');
    btnGroup.alignment = 'center';
    var okBtn = btnGroup.add('button', undefined, 'Start Processing', {name:'ok'});
    var cancelBtn = btnGroup.add('button', undefined, 'Cancel', {name:'cancel'});
    
    // Show dialog
    if (dlg.show() != 1) return;
    
    // Validate
    if (!inputFolder || !outputFolder) {
        alert("Please select both input and output folders.");
        return;
    }
    
    // Get values
    var titleTextInput = titleInput.text;
    var subtitleTextInput = subtitleInput.text;
    // নিচের দুইটা ইনপুট আর ব্যবহার হবে না, কারণ আমরা ফন্ট সাইজ ম্যানুয়ালি সেট করবো
    // var fontSize = parseInt(fontSizeInput.text);
    // var subFontSize = parseInt(subFontSizeInput.text);
    var blockColor = makeRGB(pickedColor[0], pickedColor[1], pickedColor[2]);
    
    // EPS files
    var epsFiles = inputFolder.getFiles("*.eps");
    if (epsFiles.length === 0) {
        alert("No EPS files found in the folder.");
        return;
    }
    
    var batchNumber = 1;
    var totalFiles = epsFiles.length;
    
    for (var i = 0; i < totalFiles; i += 50) {
        // Artboard size (wide)
        var artboardWidth = 2000;
        var artboardHeight = 800;
        var doc = app.documents.add(DocumentColorSpace.RGB, artboardWidth, artboardHeight);
    
        // Block sizes (নমুনা অনুযায়ী)
        var blockWidth = 350;
        var blockHeight1 = 500; // উপরের বড় ব্লক
        var blockHeight2 = 270; // নিচের ছোট ব্লক
        var blockGap = 30;      // ব্লকের মাঝে ফাঁকা
    
        // --- উপরের বড় ব্লক ---
        var block1_top = artboardHeight; // artboard এর উপরের দিক
        var block1_left = 0;
        var colorBlock1 = doc.pathItems.rectangle(
            block1_top, block1_left, blockWidth, blockHeight1
        );
        colorBlock1.fillColor = blockColor;
        colorBlock1.stroked = false;
    
        // --- নিচের ছোট ব্লক ---
        var block2_top = artboardHeight - blockHeight1 - blockGap;
        var block2_left = 0;
        var colorBlock2 = doc.pathItems.rectangle(
            block2_top, block2_left, blockWidth, blockHeight2
        );
        colorBlock2.fillColor = blockColor;
        colorBlock2.stroked = false;
    
        // ----------- লেখার অংশ (ম্যানুয়ালি ছোট ও সুন্দর) -----------
        // --- উপরের ব্লকের মধ্যে লেখা (Main Title) ---
        var titleFontSize = 25; // ছোট ফন্ট সাইজ
        var titleMarginX = 50;  // ব্লকের দুই পাশে মার্জিন
        var titleMarginY = 50;  // ব্লকের উপর-নিচে মার্জিন
        var titleText = doc.textFrames.add();
        titleText.contents = titleTextInput.toUpperCase();
        titleText.textRange.characterAttributes.size = titleFontSize;
        titleText.textRange.characterAttributes.fillColor = makeWhite();
        titleText.textRange.justification = Justification.CENTER;
        titleText.width = blockWidth - titleMarginX * 2;
        titleText.height = blockHeight1 - titleMarginY * 2;
        titleText.left = block1_left + titleMarginX;
        titleText.top = block1_top - titleMarginY;
        try {
            titleText.textRange.characterAttributes.textFont = app.textFonts.getByName("Arial-BoldMT");
        } catch(e) {}
    
        // --- নিচের ব্লকের মধ্যে লেখা (Subtitle) ---
        var subFontSize = 25; // ছোট ফন্ট সাইজ
        var subMarginX = 50;
        var subMarginY = 50;
        var subtitleText = doc.textFrames.add();
        subtitleText.contents = subtitleTextInput.toUpperCase();
        subtitleText.textRange.characterAttributes.size = subFontSize;
        subtitleText.textRange.characterAttributes.fillColor = makeWhite();
        subtitleText.textRange.justification = Justification.CENTER;
        subtitleText.width = blockWidth - subMarginX * 2;
        subtitleText.height = blockHeight2 - subMarginY * 2;
        subtitleText.left = block2_left + subMarginX;
        subtitleText.top = block2_top - subMarginY;
        try {
            subtitleText.textRange.characterAttributes.textFont = app.textFonts.getByName("Arial-BoldMT");
        } catch(e) {}
        // ----------- লেখার অংশ শেষ -----------
    
        // Grid settings (right side)
        var gridLeft = blockWidth + 30;
        var gridTop = artboardHeight - 30;
        var gridWidth = artboardWidth - gridLeft - 30;
        var gridHeight = artboardHeight - 60;
        var rows = 5, cols = 10;
        var cellWidth = gridWidth / cols;
        var cellHeight = gridHeight / rows;
    
        // Place icons
        for (var j = 0; j < 50; j++) {
            var fileIndex = i + j;
            if (fileIndex >= totalFiles) break;
    
            var row = Math.floor(j / cols);
            var col = j % cols;
            var xPos = gridLeft + col * cellWidth;
            var yPos = gridTop - row * cellHeight;
    
            var epsFile = epsFiles[fileIndex];
            var placedItem = doc.placedItems.add();
            placedItem.file = epsFile;
    
            // Maintain aspect ratio and scale to fit cell (90%)
            var scaleFactor = Math.min(
                (cellWidth * 0.9) / placedItem.width,
                (cellHeight * 0.9) / placedItem.height
            );
            placedItem.width *= scaleFactor;
            placedItem.height *= scaleFactor;
            placedItem.left = xPos + (cellWidth - placedItem.width) / 2;
            placedItem.top = yPos - (cellHeight - placedItem.height) / 2;
            placedItem.embed();
        }
    
        // Add white background (optional)
        var backgroundLayer = doc.layers.add();
        backgroundLayer.name = "Background";
        var rect = backgroundLayer.pathItems.rectangle(
            artboardHeight, 0, artboardWidth, artboardHeight
        );
        rect.fillColor = makeWhite();
        rect.stroked = false;
        backgroundLayer.zOrder(ZOrderMethod.SENDTOBACK);
    
        // Save EPS
        var outputEPS = new File(outputFolder.fsName + "/Batch_" + batchNumber + ".eps");
        var epsOptions = new EPSSaveOptions();
        epsOptions.compatibility = Compatibility.ILLUSTRATOR10;
        doc.saveAs(outputEPS, epsOptions);
    
        // Export JPG
        var outputJPG = new File(outputFolder.fsName + "/Batch_" + batchNumber + ".jpg");
        var jpgOptions = new ExportOptionsJPEG();
        jpgOptions.qualitySetting = 100;
        jpgOptions.horizontalScale = 100;
        jpgOptions.verticalScale = 100;
        jpgOptions.artBoardClipping = true;
        doc.exportFile(outputJPG, ExportType.JPEG, jpgOptions);
    
        doc.close(SaveOptions.DONOTSAVECHANGES);
        batchNumber++;
    }
    
    alert("All batches processed successfully!");
    

    }

    // Helper function for white color function makeWhite() { var white = new RGBColor(); white.red = 255; white.green = 255; white.blue = 255; return white; }

    // Helper: RGBColor function makeRGB(r, g, b) { var rgb = new RGBColor(); rgb.red = r; rgb.green = g; rgb.blue = b; return rgb; }

    main(); এই কোডটি তুমি ভালো করে পর্যবেক্ষণ করো এবং আমাকে বলে যে লেখার জন্য যে কোডটি ব্যবহার করা হয়েছে সেটি পরিবর্তন করা যাবে কি না।

  2. Assistant

    এই কোডটি পর্যবেক্ষণ করে দেখছি যে, লেখার জন্য যে কোড ব্যবহার করা হয়েছে তা অবশ্যই পরিবর্তন করা যাবে। বর্তমানে কোডে কিছু সমস্যা রয়েছে:

    বর্তমান সমস্যা:

    1. ফন্ট সাইজ ইনপুট নেওয়া হলেও ব্যবহার করা হচ্ছে না (ম্যানুয়ালি 25 সেট করা)
    2. টেক্সট ফ্রেমের height সেট করা হচ্ছে যা multiline টেক্সটের জন্য সমস্যা করতে পারে
    3. টেক্সট alignment এর জন্য শুধু justification ব্যবহার করা হচ্ছে

    পরিবর্তনের সুপারিশ:

    // ----------- লেখার অংশ (উন্নত ভার্সন) -----------
    // --- উপরের ব্লকের মধ্যে লেখা (Main Title) ---
    var titleFontSize = parseInt(fontSizeInput.text) || 60; // ইনপুট থেকে নিবে
    var titleText = doc.textFrames.add();
    titleText.contents = titleTextInput.toUpperCase();
    
    // টেক্সট স্টাইল সেট করা
    var titleStyle = titleText.textRange.characterAttributes;
    titleStyle.size = titleFontSize;
    titleStyle.fillColor = makeWhite();
    titleStyle.tracking = 50; // অক্ষরের মাঝে স্পেস
    
    // ফন্ট সেট করা (বিকল্প সহ)
    try {
        titleStyle.textFont = app.textFonts.getByName("Arial-BoldMT");
    } catch(e) {
        try {
            titleStyle.textFont = app.textFonts.getByName("ArialMT");
        } catch(e2) {}
    }
    
    // পজিশন ও alignment
    titleText.textRange.justification = Justification.CENTER;
    titleText.left = block1_left + 20;
    titleText.top = block1_top - 100; // উপর থেকে নিচে
    titleText.width = blockWidth - 40;
    
    // Multiline টেক্সটের জন্য line spacing
    titleText.textRange.paragraphAttributes.leading = titleFontSize * 1.2;
    
    // --- নিচের ব্লকের মধ্যে লেখা (Subtitle) ---
    var subFontSize = parseInt(subFontSizeInput.text) || 48;
    var subtitleText = doc.textFrames.add();
    subtitleText.contents = subtitleTextInput.toUpperCase();
    
    var subStyle = subtitleText.textRange.characterAttributes;
    subStyle.size = subFontSize;
    subStyle.fillColor = makeWhite();
    subStyle.tracking = 30;
    
    // Vertical centering এর জন্য
    subtitleText.textRange.justification = Justification.CENTER;
    subtitleText.left = block2_left + 20;
    subtitleText.top = block2_top - (blockHeight2 / 2) + (subFontSize / 2);
    subtitleText.width = blockWidth - 40;
    

    অতিরিক্ত উন্নতির জন্য:

    // টেক্সট এফেক্ট যোগ করা (ঐচ্ছিক)
    function addTextEffects(textFrame) {
        // ড্রপ শ্যাডো
        textFrame.opacity = 100;
        
        // স্ট্রোক যোগ করা
        var textStroke = textFrame.textRange.characterAttributes;
        textStroke.strokeColor = makeRGB(0, 0, 0);
        textStroke.strokeWeight = 0.5;
        textStroke.stroked = true;
    }
    
    // ব্যবহার:
    addTextEffects(titleText);
    addTextEffects(subtitleText);
    

    এই পরিবর্তনগুলো করলে:

    • ইউজার ইনপুট অনুযায়ী ফন্ট সাইজ কাজ করবে
    • টেক্সট আরও সুন্দরভাবে align হবে
    • Multiline টেক্সট ভালোভাবে কাজ করবে
    • প্রয়োজনে টেক্সট এফেক্ট যোগ করা যাবে

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.