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

Determining Student Pass/Incomplete Status Script

Community Beginner ,
Nov 22, 2024 Nov 22, 2024

Copy link to clipboard

Copied

Hello Again

 

I have a table of Studen'ts Results

 

I asked Claudia AI to write a script

 

If a pupil doesn't have any degree less than 5 then he is "ناجح"

If a pupil have a degree or two less than 5 then he is "مكمل من"

If a pupil have three degrees less than 5 then he is "راسب"

 

I asked AI to write a result in the last row of the selected row/rows

But it didn't work

 

Any help to make it work?

 

Demo document in the attachments

 

Thanks in advanced!

 

// تأكد من وجود مستند نشط
if (app.documents.length > 0) {
    var myDoc = app.activeDocument;
    
    // التحقق من وجود تحديد
    if (app.selection.length > 0) {
        try {
            // الحصول على الخلايا المحددة
            var selectedCells = app.selection[0].cells;
            
            // التكرار على كل صف محدد
            var currentRow = selectedCells[0].rowIndex;
            var rowGrades = [];
            var resultCell;
            
            for (var i = 0; i < selectedCells.length; i++) {
                var cell = selectedCells[i];
                
                // إذا انتقلنا لصف جديد
                if (cell.rowIndex !== currentRow) {
                    // تحديد النتيجة للصف السابق
                    processGrades(rowGrades, resultCell);
                    
                    // بدء صف جديد
                    currentRow = cell.rowIndex;
                    rowGrades = [];
                }
                
                // تخزين آخر خلية كخلية النتيجة
                if (i === selectedCells.length - 1 || 
                    selectedCells[i + 1].rowIndex !== currentRow) {
                    resultCell = cell;
                } else {
                    // تحويل محتوى الخلية إلى رقم وإضافته للدرجات
                    var grade = parseFloat(cell.contents.replace(/[^\d.-]/g, ''));
                    if (!isNaN(grade)) {
                        rowGrades.push(grade);
                    }
                }
            }
            
            // معالجة آخر صف
            if (rowGrades.length > 0) {
                processGrades(rowGrades, resultCell);
            }
            
        } catch (e) {
            alert("خطأ: " + e);
        }
    } else {
        alert("الرجاء تحديد الخلايا في الجدول أولاً");
    }
} else {
    alert("الرجاء فتح مستند InDesign أولاً");
}

// دالة لمعالجة الدرجات وكتابة النتيجة
function processGrades(grades, resultCell) {
    if (!grades.length || !resultCell) return;
    
    // حساب عدد الدرجات أقل من 5
    var failedCount = grades.filter(function(grade) {
        return grade < 5;
    }).length;
    
    // تحديد النتيجة
    var result = "";
    var resultColor;
    
    if (failedCount === 0) {
        result = "ناجح";
        resultColor = [100, 0, 100, 0]; // CMYK أخضر
    } else if (failedCount === 1) {
        result = "مكمل";
        resultColor = [0, 50, 100, 0]; // CMYK برتقالي
    } else if (failedCount === 2) {
        result = "مكمل";
        resultColor = [0, 50, 100, 0]; // CMYK برتقالي
    } else {
        result = "راسب";
        resultColor = [0, 100, 100, 0]; // CMYK أحمر
    }
    
    // إضافة "من" للمكمل
    if (result === "مكمل") {
        result = "مكمل من " + failedCount;
    }
    
    // كتابة النتيجة في الخلية
    resultCell.contents = result;
    
    // تنسيق النص
    var resultText = resultCell.texts[0];
    resultText.pointSize = 12;
    resultText.justification = Justification.CENTER_ALIGN;
    
    // تعريف الألوان إذا لم تكن موجودة
    try {
        var colorName = "نتيجة " + (result.indexOf("مكمل") >= 0 ? "مكمل" : result);
        var resultColorObj = myDoc.colors.itemByName(colorName);
        if (!resultColorObj.isValid) {
            resultColorObj = myDoc.colors.add({
                name: colorName,
                model: ColorModel.PROCESS,
                colorValue: resultColor
            });
        }
        resultText.fillColor = resultColorObj;
    } catch (e) {
        // في حالة وجود خطأ في إنشاء اللون
    }
}
TOPICS
UXP Scripting

Views

60

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 ,
Dec 02, 2024 Dec 02, 2024

Copy link to clipboard

Copied

up

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 ,
16 hours ago 16 hours ago

Copy link to clipboard

Copied

up

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 ,
14 hours ago 14 hours ago

Copy link to clipboard

Copied

LATEST

First, most users here, unfortunately, don't understand Arabic so it's hard to get the full understanding of your script as all comments and other data there are in Arabic.

 

Second, you didn't say what exactly doesn't work, what troubleshooting steps you undertook to remedy the issue, what were the results of those steps, and what specific lines of the script you have identified as the culprit for the error as a result of this troubleshooting.

 

Third, I wonder if it's possible to feed the error as well as other relevant info to Claudia AI and request a solution for the script it wrote?

 

 

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