Загрузка...

Script for creating a calendar grid in Photoshop

Thread in Programming created by мамы Jun 13, 2025. 161 view

  1. мамы
    мамы Topic starter Jun 13, 2025 552 Jan 3, 2022
    есть скрипт готовый для адоб илюстартора - https://drive.google.com/file/d/1i5D0TWcWFqkJSSFC5lgFED37ppE1ZZq0/view?usp=drive_link
    // Calendar Premaker (ru)
    // Horisontal Orientation
    // Euro Style (Monday first)

    // version 0.3.2
    // (c) vd
    // ai-js@mail.ru



    var sMS = "\u042F\u043D\u0432\u0430\u0440\u044C,\u0424\u0435\u0432\u0440\u0430\u043B\u044C,\u041C\u0430\u0440\u0442,\u0410\u043F\u0440\u0435\u043B\u044C,\u041C\u0430\u0439,\u0418\u044E\u043D\u044C,\u0418\u044E\u043B\u044C,\u0410\u0432\u0433\u0443\u0441\u0442,\u0421\u0435\u043D\u0442\u044F\u0431\u0440\u044C,\u041E\u043A\u0442\u044F\u0431\u0440\u044C,\u041D\u043E\u044F\u0431\u0440\u044C,\u0414\u0435\u043A\u0430\u0431\u0440\u044C";
    var sDS = "\u043F\u043D,\u0432\u0442,\u0441\u0440,\u0447\u0442,\u043F\u0442,\u0441\u0431,\u0432\u0441";
    var sHS = "1/1,2/1,7/1,8/3,1/5,2/5,9/5,12/6,7/11,12/12";


    var pMS = "\u0412\u0432\u0435\u0434\u0438\u0442\u0435\u0020\u043D\u0430\u0437\u0432\u0430\u043D\u0438\u0435\u0020\u043C\u0435\u0441\u044F\u0446\u0435\u0432\u0020\u0028\u0447\u0435\u0440\u0435\u0437\u0020\u0437\u0430\u043F\u044F\u0442\u0443\u044E\u0029\n\u0418\u043B\u0438\u0020\u043E\u0441\u0442\u0430\u0432\u044C\u0442\u0435\u0020\u0431\u0435\u0437\u0020\u0438\u0437\u043C\u0435\u043D\u0435\u043D\u0438\u0439";
    var pDS = "\u0412\u0432\u0435\u0434\u0438\u0442\u0435\u0020\u043D\u0430\u0437\u0432\u0430\u043D\u0438\u0435\u0020\u0434\u043D\u0435\u0439\u0020\u043D\u0435\u0434\u0435\u043B\u0438\u0020\u0028\u0447\u0435\u0440\u0435\u0437\u0020\u0437\u0430\u043F\u044F\u0442\u0443\u044E\u0029\n\u0418\u043B\u0438\u0020\u043E\u0441\u0442\u0430\u0432\u044C\u0442\u0435\u0020\u0431\u0435\u0437\u0020\u0438\u0437\u043C\u0435\u043D\u0435\u043D\u0438\u0439";
    var pHS = "\u0412\u0432\u0435\u0434\u0438\u0442\u0435\u0020\u0434\u0430\u0442\u044B\u0020\u0432\u044B\u0445\u043E\u0434\u043D\u044B\u0445,\u0020\u043F\u043E\u0020\u0442\u0430\u043A\u043E\u043C\u0443\u0020\u043F\u0440\u0430\u0432\u0438\u043B\u0443\u0020\u0414\u002F\u041C\u005B,\u0414\u002F\u041C,\u0414\u002F\u041C\u002E\u002E\u002E\u005D";


    var AppCap = "Calendar Premaker (for Adobe Illustrator CS)\n\n";
    var iStr = "\u0414\u043B\u044F\u0020\u043F\u043E\u0434\u0441\u0442\u0440\u043E\u0439\u043A\u0438\u0020\u0438\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0439\u0442\u0435:\n\n"+
    "Window -> Type -> Paragraph Styles\n"+
    "Window -> Type -> Character Styles\n"+
    "Window -> Swatches\n\n";
    var pStr = AppCap+"\u0423\u043A\u0430\u0436\u0438\u0442\u0435\u0020\u0433\u043E\u0434.\n\u041D\u0430\u043F\u0440\u0438\u043C\u0435\u0440: 2005";

    Year = 2005;
    Year = prompt(pStr, Year);
    if(Year>2000 && Year<2100 && Year != null) {

    MS = prompt(AppCap+pMS, sMS);
    if(MS){
    MC = MS.split(',',12);

    for(i=0;i<12;i++) if(MC==null) MC.push(' ');
    for(i=0;i<12;i++) if(MC=='') MC=' ';

    DS = prompt(AppCap+pDS, sDS);
    if(DS) {
    DC = DS.split(',',7);
    for(i=0;i<7;i++) if(DC==null) DC.push(' ');
    for(i=0;i<7;i++) if(DC=='') DC[i][/i]=' ';[/I][/I]

    HS = prompt(AppCap+pHS, sHS);
    if(HS == '') HS = ' ';
    if(HS) {
    HC = HS.split(',');
    HD = Array();
    for(i=0;i<HC.length;i++) {
    DM = HC[i][/i].split('/');[/I][/I]
    HD.push(DM[0],DM[1]);
    }

    makeCalendar();
    }
    }
    }
    }

    function makeCalendar() {
    CellHeight = 20;
    CellWidth = 30;

    MN = Array(31,(Year%4==0)?29:28,31,30,31,30,31,31,30,31,30,31);
    FirstDay = Math.floor((Year-2001)*5/4%7);
    FD = FirstDay;
    var DocTop = CellHeight*52;
    var docRef = documents.add(DocumentColorSpace.CMYK,CellWidth*18,DocTop+CellHeight*3);


    //
    waitRef = docRef.textFrames.add();
    waitRef.contents = "Processing...";
    waitRef.top = DocTop;
    waitRef.left = 10;
    waitRef.height = 100;
    waitRef.width = 300;
    redraw();
    //

    docRef.swatches.removeAll();
    try{docRef.characterStyles.removeAll()} catch(e){}

    var nColor = new CMYKColor();
    var nSpotColor = new SpotColor();

    var DefaultSpot = docRef.spots.add();
    nColor.cyan = 90;
    nColor.magenta = 60;
    nColor.yellow = 0;
    nColor.black = 0;
    DefaultSpot.name = "Week day color";
    DefaultSpot.colorType = ColorModel.PROCESS;
    DefaultSpot.color = nColor;

    var HolidaySpot = docRef.spots.add();
    nColor.cyan = 0;
    nColor.magenta = 90;
    nColor.yellow = 60;
    nColor.black = 0;
    HolidaySpot.name = "Holiday color";
    HolidaySpot.colorType = ColorModel.PROCESS;
    HolidaySpot.color = nColor;

    var DaySpot = docRef.spots.add();
    nColor.cyan = 0;
    nColor.magenta = 0;
    nColor.yellow = 0;
    nColor.black = 70;
    DaySpot.name = "Color of caption of week day";
    DaySpot.colorType = ColorModel.PROCESS;
    DaySpot.color = nColor;

    var HolydayDaySpot = docRef.spots.add();
    nColor.cyan = 0;
    nColor.magenta = 60;
    nColor.yellow = 20;
    nColor.black = 50;
    HolydayDaySpot.name = "Color of caption of weekend";
    HolydayDaySpot.colorType = ColorModel.PROCESS;
    HolydayDaySpot.color = nColor;

    var CaptionSpot = docRef.spots.add();
    nColor.cyan = 0;
    nColor.magenta = 0;
    nColor.yellow = 0;
    nColor.black = 100;
    CaptionSpot.name = "Color of caption of month";
    CaptionSpot.colorType = ColorModel.PROCESS;
    CaptionSpot.color = nColor;


    var charAttr;
    var paraAttr;
    var DefaultStyle = docRef.characterStyles.add("Week day");
    var HolidayStyle = docRef.characterStyles.add("Holyday");
    var DayCapStyle = docRef.characterStyles.add("Caption of week day");
    var HolydayCapStyle = docRef.characterStyles.add("Caption of weekend");
    var CaptionsStyle = docRef.characterStyles.add("Caption of month");



    charAttr = DefaultStyle.characterAttributes;
    //charAttr.size = 14;
    nSpotColor.spot = DefaultSpot;
    charAttr.fillColor = nSpotColor;

    charAttr = HolidayStyle.characterAttributes;
    //charAttr.size = 14;
    nSpotColor.spot = HolidaySpot;
    charAttr.fillColor = nSpotColor;

    charAttr = DayCapStyle.characterAttributes;
    //charAttr.size = 14;
    nSpotColor.spot = DaySpot;
    charAttr.fillColor = nSpotColor;

    charAttr = HolydayCapStyle.characterAttributes;
    //charAttr.size = 14;
    nSpotColor.spot = HolydayDaySpot;
    charAttr.fillColor = nSpotColor;

    charAttr = CaptionsStyle.characterAttributes;
    //charAttr.size = 14;
    nSpotColor.spot = CaptionSpot;
    charAttr.fillColor = nSpotColor;


    var paraDayStyle = docRef.paragraphStyles.add("Dates");
    paraAttr = paraDayStyle.paragraphAttributes;
    paraAttr.justification = Justification.RIGHT;

    var paraWeekDayStyle = docRef.paragraphStyles.add("Days of week");
    paraAttr = paraWeekDayStyle.paragraphAttributes;
    paraAttr.justification = Justification.RIGHT;

    var paraMonthStyle = docRef.paragraphStyles.add("Months");
    paraAttr = paraMonthStyle.paragraphAttributes;
    paraAttr.justification = Justification.LEFT;



    LeftMargin = CellWidth;
    for(m=0; m<6; m++){
    textRef = docRef.textFrames.add();
    textRef.contents = MC[m];
    textRef.top = DocTop - m*9*CellHeight+CellHeight*2;
    textRef.left = CellWidth + LeftMargin;
    CaptionsStyle.applyTo(textRef.textRange)
    paraMonthStyle.applyTo(textRef.paragraphs[0], true);

    for(i=0; i<7; i++){
    textRef = docRef.textFrames.add();
    textRef.contents = DC[i][/i];[/I][/I]
    textRef.top = DocTop - m*9*CellHeight+CellHeight;
    textRef.left = i*CellWidth + LeftMargin;
    (i<6) ? DayCapStyle.applyTo(textRef.textRange) : HolydayCapStyle.applyTo(textRef.textRange);
    paraWeekDayStyle.applyTo(textRef.paragraphs[0], true);
    }
    for(d=0; d<MN[m]; d++){
    textRef = docRef.textFrames.add();
    textRef.contents = d+1;
    textRef.top = DocTop - ((Math.floor((FD+d)/7)*CellHeight) + m*9*CellHeight);
    textRef.left = (FD+d)%7*CellWidth + LeftMargin;
    paraDayStyle.applyTo(textRef.paragraphs[0], true);
    if ((FD+d+1)%7) DefaultStyle.applyTo(textRef.textRange);
    else HolidayStyle.applyTo(textRef.textRange);
    if (isHoliday(d+1,m+1)) HolidayStyle.applyTo(textRef.textRange);
    }
    FD = (FD+d)%7;
    }

    LeftMargin = CellWidth*9;
    for(m=6; m<12; m++){
    textRef = docRef.textFrames.add();
    textRef.contents = MC[m];
    textRef.top = DocTop - (m-6)*9*CellHeight+CellHeight*2;
    textRef.left = CellWidth + LeftMargin;
    CaptionsStyle.applyTo(textRef.textRange)
    paraMonthStyle.applyTo(textRef.paragraphs[0], true);

    for(i=0; i<7; i++){
    textRef = docRef.textFrames.add();
    textRef.contents = DC[i][/i];[/I][/I]
    textRef.top = DocTop - (m-6)*9*CellHeight+CellHeight;
    textRef.left = i*CellWidth + LeftMargin;
    (i<6) ? DayCapStyle.applyTo(textRef.textRange) : HolydayCapStyle.applyTo(textRef.textRange);
    paraWeekDayStyle.applyTo(textRef.paragraphs[0], true);
    }
    for(d=0; d<MN[m]; d++){
    textRef = docRef.textFrames.add();
    textRef.contents = d+1;
    textRef.top = DocTop - ((Math.floor((FD+d)/7)*CellHeight) + (m-6)*9*CellHeight);
    textRef.left = (FD+d)%7*CellWidth + LeftMargin;
    paraDayStyle.applyTo(textRef.paragraphs[0], true);
    if ((FD+d+1)%7) DefaultStyle.applyTo(textRef.textRange);
    else HolidayStyle.applyTo(textRef.textRange);
    if (isHoliday(d+1,m+1)) HolidayStyle.applyTo(textRef.textRange);
    }
    FD = (FD+d)%7;
    }

    waitRef.remove();
    redraw();

    alert(iStr);
    }

    function isHoliday(day,month)
    {
    var i;
    for(i=0; i<HD.length; i+=2){
    if(day==HD[i][/i] && month==HD[i+1]) return true;[/I][/I]
    }
    return false;
    }
    [/i][/i][/i][/i][/i]

    мне эту шляпу надо переделать для адоб фотошопа (в програмирование ваще не шарю,пробовал через чат гпт прогнать пишет не работающую хуйню)мб кто знает чо делать кому не лень сидеть копаться в коде помагите...
     
  2. posu
    posu Jun 13, 2025 183 Jul 25, 2019
    Скинь, как календарь выглядит. Сейчас пробую переписывать скрипт под Photoshop, но не знаю, как он выглядит в оригинале. Illustrator лень качать
     
    1. posu
      мамы, Как быстро Illustrator отрисовал календарь?
    2. мамы Topic starter
      posu, секунд 30 что ли
  3. posu
    posu Jun 13, 2025 183 Jul 25, 2019
    Тестировал в Adobe Photoshop 2019. По времени заняло 10-15 мин
    JS
    const MONTHS = "Январь,Февраль,Март,Апрель,Май,Июнь,Июль,Август,Сентябрь,Октябрь,Ноябрь,Декабрь";
    const DAYS = "пн,вт,ср,чт,пт,сб,вс";
    const HOLIDAYS = "1/1,2/1,7/1,8/3,1/5,2/5,9/5,12/6,7/11,12/12";

    const CELL_WIDTH = 60;
    const CELL_HEIGHT = 40;
    const COLS = 7;
    const ROWS = 6;
    const MARGIN = 100;
    const SPACING = 20;

    var year = parseInt(prompt("Календарь\nВведите год (2000–2100):", "2025"), 10);
    if (!(year >= 2000 && year <= 2100)) exit();

    var months = prompt("Введите месяцы (через запятую):", MONTHS).split(",");
    var days = prompt("Введите дни недели (через запятую):", DAYS).split(",");
    var holidays = parseHolidays(prompt("Введите даты праздников (д/м, через запятую):", HOLIDAYS));

    var dayCounts = [31, isLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
    var firstDayOffset = getFirstDayOffset(year);

    app.preferences.rulerUnits = Units.PIXELS;

    var blockW = CELL_WIDTH * COLS + SPACING * 2;
    var blockH = CELL_HEIGHT * ROWS + CELL_HEIGHT * 3 + SPACING;

    var docW = blockW * 2 + MARGIN * 2;
    var docH = blockH * 6 + MARGIN;

    var doc = app.documents.add(docW, docH, 72, "Календарь " + year);

    var offsetDay = firstDayOffset;

    for (var m = 0; m < 12; m++) {
    var half = Math.floor(m / 6);
    var localIndex = m % 6;

    var offsetX = MARGIN + half * (docW / 2);
    var offsetY = MARGIN + localIndex * (CELL_HEIGHT * ROWS + CELL_HEIGHT * 3 + SPACING);

    var group = doc.layerSets.add();
    group.name = (months[m] || "Месяц") + " " + year;

    addTextGroup(months[m] || " ", offsetX, offsetY, 24, [0, 0, 120], "left", group);

    for (var d = 0; d < 7; d++) {
    var dx = offsetX + d * CELL_WIDTH;
    var dy = offsetY + CELL_HEIGHT;
    addTextGroup(days[d] || " ", dx, dy, 16, [0, 0, 120], "center", group);
    }

    for (var d = 1; d <= dayCounts[m]; d++) {
    var totalOffset = offsetDay + d - 1;
    var col = totalOffset % 7;
    var row = Math.floor(totalOffset / 7);

    var dx = offsetX + col * CELL_WIDTH;
    var dy = offsetY + (row + 2) * CELL_HEIGHT;

    var isHol = isHoliday(d, m + 1, holidays);
    var isWeekend = (col === 6);
    var colr = (isHol || isWeekend) ? [200, 0, 0] : [0, 0, 0];

    addTextGroup(d.toString(), dx, dy, 20, colr, "center", group);
    }

    offsetDay = (offsetDay + dayCounts[m]) % 7;
    }

    function isLeapYear(y) {
    return (y % 4 === 0 && (y % 100 !== 0 || y % 400 === 0));
    }

    function getFirstDayOffset(y) {
    var d = new Date(y, 0, 1);
    return (d.getDay() + 6) % 7;
    }

    function parseHolidays(str) {
    var result = [];
    if (!str) return result;
    var parts = str.split(",");
    for (var i = 0; i < parts.length; i++) {
    var dm = parts[i].split("/");
    if (dm.length === 2) {
    result.push({ d: parseInt(dm[0]), m: parseInt(dm[1]) });
    }
    }
    return result;
    }

    function isHoliday(d, m, list) {
    for (var i = 0; i < list.length; i++) {
    if (list[i].d === d && list[i].m === m) return true;
    }
    return false;
    }

    function addTextGroup(txt, x, y, size, rgb, align, group) {
    var layer = group.artLayers.add();
    layer.kind = LayerKind.TEXT;
    var ti = layer.textItem;
    ti.contents = txt;
    ti.position = [x, y];
    ti.size = size;
    var color = new SolidColor();
    color.rgb.red = rgb[0];
    color.rgb.green = rgb[1];
    color.rgb.blue = rgb[2];
    ti.color = color;
    ti.justification = (align === "center") ? Justification.CENTER : (align === "right") ? Justification.RIGHT : Justification.LEFT;
    }
    [IMG]
     
    1. мамы Topic starter
      posu,бля мужик
    2. мамы Topic starter
      posu, красавчик ваще спс огромное!!! выручил крч
Top
Loading...