Script to remove all digits from the document except for the text box according to its size
Hi All
I want a script to remove all digits from the document except for the text box according to its size
( width and height ) . asked chat gpt 4 , replied with this code but It doesn't work
What is the problem please ?
Thanks
---------------------------------------------------------------------------------------
// Create a dialog with input fields for width and height
var dialog = new Window("dialog", "Excluded Text Box Size");
dialog.orientation = "column";
dialog.alignChildren = "left";
var widthGroup = dialog.add("group");
widthGroup.add("statictext", undefined, "Width (mm):");
var widthInput = widthGroup.add("edittext", undefined, "50");
widthInput.characters = 10;
var heightGroup = dialog.add("group");
heightGroup.add("statictext", undefined, "Height (mm):");
var heightInput = heightGroup.add("edittext", undefined, "25");
heightInput.characters = 10;
var buttonGroup = dialog.add("group");
var okButton = buttonGroup.add("button", undefined, "OK");
okButton.onClick = function() {
var specifiedWidthInMm = parseFloat(widthInput.text); // Convert input to number
var specifiedHeightInMm = parseFloat(heightInput.text); // Convert input to number
dialog.close();
removeDigitsExceptSpecifiedSize(specifiedWidthInMm, specifiedHeightInMm);
};
var cancelButton = buttonGroup.add("button", undefined, "Cancel");
cancelButton.onClick = function() {
dialog.close();
};
dialog.show();
// Remove Digits Function
function removeDigitsExceptSpecifiedSize(specifiedWidthInMm, specifiedHeightInMm) {
var doc = app.activeDocument;
var textFrames = doc.textFrames;
for (var i = 0; i < textFrames.length; i++) {
var textFrame = textFrames[i];
var frameBounds = textFrame.geometricBounds;
var frameWidth = frameBounds[3] - frameBounds[1];
var frameHeight = frameBounds[2] - frameBounds[0];
var specifiedWidthInPoints = specifiedWidthInMm * 2.83464567; // Convert mm to points
var specifiedHeightInPoints = specifiedHeightInMm * 2.83464567; // Convert mm to points
if (frameWidth !== specifiedWidthInPoints || frameHeight !== specifiedHeightInPoints) {
var textContent = textFrame.parentStory.contents;
var textWithoutDigits = textContent.replace(/\d/g, '');
textFrame.parentStory.contents = textWithoutDigits;
}
}
}
