Error: an Illustrator error occurred: 1346458189 (‘PARM’) (illustrator v2024)

I have been getting these errors very often in almost my simplest scripts for a long time. I am getting this warning even though I have tried all the alternatives thinking it may be in the coordinate system. When I researched, there are people who get similar errors but no definitive solution has been provided.

//this script task: Adds the selected objects to the page in cm.
// The error it gives every now and then is:
// Error: an Illustrator error occurred: 1346458189 ('PARM')
#target illustrator
offsetT=0 
var myDoc = app.activeDocument;
myDoc.rulerOrigin = [0,0];
var sel = app.selection; //sel as selections array.
var str = "";
function essenziki() {
    if(sel.length==0){
        alert("choose something first");
        return
     }

for (var i = 0; i < sel.length; i++) { //loop and check each selected objects
  str += (pt2mm(sel[i].width) / 10+offsetT).toFixed(0) + "*" + (pt2mm(sel[i].height) / 10+offsetT).toFixed(0)+ "n";
}
str = str.replace(/n$/, ''); // Replace last line break to empty symbol
var tx = myDoc.textFrames.add();
    tx.contents = str;
tx.textRange.characterAttributes.size=150; 
tx.textRange.characterAttributes.textFont = app.textFonts.getByName('Arial-BoldMT');

app.executeMenuCommand("deselectall"); //deselect all abjects

var cmykColor = new CMYKColor();
cmykColor.cyan = 34;
cmykColor.magenta = 49;
cmykColor.yellow = 19;
cmykColor.black = 27;
tx.textRange.characterAttributes.fillColor = cmykColor; 

app.executeMenuCommand("deselectall"); //deselect all abjects
    tx.selected = true; 

function pt2mm(n){
  return n * 0.35277778;
}

};
essenziki();

if (app.selection.length > 0) {
    var selectedItem = app.selection[0]; // Get the first selected item

    // Get the center of the current view in document coordinates
    var viewCenter = app.activeDocument.activeView.centerPoint; // [x, y] of view center in document coordinates

    // Calculate the center of the selected item
    var itemBounds = selectedItem.geometricBounds; // [left, top, right, bottom]
    var itemCenterX = (itemBounds[0] + itemBounds[2]) / 2;
    var itemCenterY = (itemBounds[1] + itemBounds[3]) / 2;

    // Calculate the offset to move the item to the center of the view
    var offsetX = viewCenter[0] - itemCenterX;
    var offsetY = viewCenter[1] - itemCenterY;

    // Move the item to the center of the view
    selectedItem.translate(offsetX, offsetY);
}