Hi @Laf Tasarim Ofisi
Many thanks for the sample file. It was very helpful.
The following script replaces all placeholders ‘XXX ...’ on the predefined levels ‘info’ and ‘name’ in all ai files with the name of the parent folder as required. The folder can be selected after starting the script.
Sidenote:
I have switched off automatic saving and closing. After testing, you can switch on automatic saving and closing by removing the comment characters ‘//’ in line 22.
Try it:
// https://community.adobe.com/t5/illustrator-discussions/replacing-quot-xxx-xxx-xxx-quot-texts-with-folder-name-in-illustrator/td-p/14643582
// thread: Replacing "XXX XXX XXX" texts with folder name in Illustrator
// based on sample file: layout.ai
// regards pixxxelschubser
// Script fails if there is no layer ‘info’ and no layer ‘name’ in the document
// After testing, you can switch on automatic saving and closing by removing the comment characters ‘//’ in line 22
var sourceFolder = Folder.selectDialog ("Select Folder with ai files");
if( sourceFolder) {
var sourceFiles = sourceFolder.getFiles(/\.ai$/i);
if( sourceFiles) {
var sFolLen = sourceFiles.length;
for (var i = sFolLen-1; i>=0; i--) {
app.userInteractionLevel=UserInteractionLevel.DONTDISPLAYALERTS;
app.open(sourceFiles[i]);
app.userInteractionLevel=UserInteractionLevel.DISPLAYALERTS;
var aDoc = app.activeDocument;
main ();
//aDoc.close(SaveOptions.SAVECHANGES); // Activate this line to automatically save and close the file
}
}
};
function main () {
var folNme = decodeURI (aDoc.path).split("/").reverse();
changeTxt("info", folNme);
changeTxt("name", folNme);
return;
};
function changeTxt(nme, f) {
//var givenTxt = "XXX XXX XXX XXX"; // activate if you need an additional test for ‘XXX ...’
var lay = aDoc.layers.getByName(nme);
var tfLen = lay.textFrames.length;
for (var j=0; j<tfLen; j++) {
var txt = lay.textFrames[j];
//if( txt.contents == givenTxt) { // activate if you need an additional test for ‘XXX ...’
txt.contents = f[0];
//} // activate if you need an additional test for ‘XXX ...’
}
return;
};
... View more