Can you find errors on this illustrator script and fix it? Here is the script:// Check…
- User
Can you find errors on this illustrator script and fix it? Here is the script:// Check if a document is open if (app.documents.length > 0) { var doc = app.activeDocument; var docName = doc.name.split('.')[0]; // Get the name of the current document without the extension
codevar folderPath = Folder.selectDialog("Select the folder containing flag files"); if (folderPath) { var files = folderPath.getFiles("*.ai"); // Loop through all AI files in the selected folder for (var i = 0; i < files.length; i++) { var fileName = files[i].name.split('.')[0]; // Get the name of the file without the extension var flagName = fileName.replace('_', ' '); // Format the file name // Check if the artboard name matches the flag name for (var j = 0; j < doc.artboards.length; j++) { var artboardName = doc.artboards[j].name.replace('_', ' '); // Format the artboard name if (artboardName.toLowerCase() === flagName.toLowerCase()) { var flagFile = new File(files[i]); // Place the flag file on the current artboard var placedItem = doc.placedItems.add(); placedItem.file = flagFile; // Get the dimensions of the placed item var placedWidth = placedItem.width; var placedHeight = placedItem.height; // Calculate the scaling factor for width and height separately var widthScaleFactor = artboardWidth / placedWidth; var heightScaleFactor = artboardHeight / placedHeight; // Choose the smaller scaling factor to ensure that both width and height fit within the artboard var scaleFactor = Math.min(widthScaleFactor, heightScaleFactor); // Ensure that the scaled dimensions are not less than the minimum allowed value if (placedWidth * scaleFactor >= 0.01 && placedHeight * scaleFactor >= 0.01) { placedItem.width *= scaleFactor; placedItem.height *= scaleFactor; // Center the placed artwork on the artboard placedItem.position = [artboardWidth / 2, artboardHeight / 2]; } else { alert("Error: Scaling resulted in dimensions less than minimum allowed value."); } } } } alert("Flags placed on relevant artboards."); } else { alert("No folder selected. Please select a folder containing flag files."); } - Assistant
- User
It worked except of some country names. Such as Holy See, Heard Island and McDonald Islands, Isle of Man and etc. File names are written as : HOLY SEE.ai, HEARD ISLAND AND MCDONALD ISLANDS.ai and etc. But at the same time some country name is written as : PAPUA_NEW_GUINEA.ai. So we need to have both options to match country names.
- Assistant