I'm -slowly- learning how to code using JavaScript in Illustrator, and I'm trying to write a script that automatically picks an image file from a given fixed folder in my hard drive and places it in a fixed position inside the Illustrator file. All of this should happen if and only if the image has the very same name of the Illustrator file itself (both without the ".something" extension)
Here's what I have so far:
doc = app.activeDocument;
//images are in this folder
var dirImages = new Folder("C:\\FolderWithImages");
var imagesList = dirImages.getFiles();
var itemToPlace;
for (var i = 0; i < imagesList.length; i++) {
var imgName = imagesList[i].name;
var documentName = activeDocument.name;
//compare image filename to current document name (both without extensions)
var imgNameNoExt = imgName.slice(0, imgName.indexOf("."));
var docuNameNoExt = documentName.slice(0, documentName.indexOf("."));
// check identical names
if( imgNameNoExt == docuNameNoExt ) {
itemToPlace.file = imagesList[i];
itemToPlace.top = myDocument.height;
itemToPlace.left = 0;
}
}
When I run it I don't get any error code, but I don't get any result either. What am I doing wrong?