Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
// reset the Find/Change dialog
app.findGrepPreferences = app.changeGrepPreferences = null;
// formulate a grep search string
app.findGrepPreferences.findWhat = '@.+?@';
// find all occurrence, last one first
f = app.activeDocument.findGrep (true);
for (i = 0; i < f.length; i++)
{
// construct file name
name = f.contents.replace (/@/g, '');
// place the pdf
f.insertionPoints[0].place (File ('/c/' + name));
}
// delete all @??@ codes
app.activeDocument.changeGrep()
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
#target indesign
picture_dir = '/d/'
app.findPreferences = app.changePreferences = null;
myStories = app.activeDocument.stories;
for (i = 0; i < myStories.length; i++)
{
picnames = myStories.contents.match (/@.+?@/g);
if (picnames != null)
{
for (j = 0; j < picnames.length; j++)
{
found = app.activeDocument.search (picnames,false,false);
for (k = found.length-1; k > -1; k--)
{
try
{
filename = found.contents.replace (/@/g, "");
found.insertionPoints[-1].place (File (picture_dir + filename));
found.remove();
}
catch(_){}
}
}
}
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
f.insertionPoints[0].place (File ('~/Desktop/Images/' + name));
Copy link to clipboard
Copied
if(app.documents.length != 0){
var myFolder = Folder.selectDialog ('Choose a folder with images');
if(myFolder != null){
// reset the Find/Change dialog
app.findGrepPreferences = app.changeGrepPreferences = null;
// formulate a grep search string
app.findGrepPreferences.findWhat = '@.+?@';
// find all occurrence, last one first
f = app.activeDocument.findGrep (true);
for (i = 0; i < f.length; i++)
{
// construct file name
name = f.contents.replace (/@/g, '');
// place the pdf
f.insertionPoints[0].place (myFolder.fsName + '/' + name);
}
// delete all @??@ codes
app.activeDocument.changeGrep()
}
}
else{
alert('Please open a document and try again.');
}
Copy link to clipboard
Copied
Dear Kasyan,
I have problem,
In my document there is more than 100 images name, when I run your script I got an error because in my directory some images is different location/path.
Regards,
Sumit
Copy link to clipboard
Copied
I just tested the script (I posted in post 20) in InDesign 2015.4 and it works for me in the same way as it worked in CS3.
Before
After
This script doesn't care about the existing images and their locations. It only places new images using the names of files found in between a pair of '@' characters and the selected folder for images.
— Kas
Copy link to clipboard
Copied
Dear Kasyan,
Thank you for quick response.
Your script is great!
My problem is, if some images are not found in selected directory then pop up error massage and stop executing next.
Below is my scenario, but my document contains more than 100 image names and in my directory there is less than 100 images found then stop executing script.
I hope you understand my problem, my english is not good.
Thanks,
Sumit
Copy link to clipboard
Copied
This should do it:
if(app.documents.length != 0){
var myFolder = Folder.selectDialog ('Choose a folder with images');
if(myFolder != null){
// reset the Find/Change dialog
app.findGrepPreferences = app.changeGrepPreferences = null;
// formulate a grep search string
app.findGrepPreferences.findWhat = '@.+?@';
// find all occurrence, last one first
var f = app.activeDocument.findGrep (true);
var missedFiles = [];
for (var i = 0; i < f.length; i++){
// construct file name
name = f.contents.replace (/@/g, '');
// place the pdf
try{
f.insertionPoints[0].place (myFolder.fsName + '/' + name);
}catch(err){
missedFiles.push(name);
}
}
// delete all @??@ codes
app.activeDocument.changeGrep();
if(missedFiles.length){
alert("The following files could not be found: " + missedFiles.join(", "));
}
}
}
else{
alert('Please open a document and try again.');
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now