Copy link to clipboard
Copied
Hi Experts,
I need a script which needs automatically place as inline image wherever specific text as XX.eps, XX.ai, come in the document. I have exactly environment as below link. Although, this is a paid script but didn't afford at my end.
http://www.nikkimgroup.com.au/features/placing-artwork
I have 250+ images to link in the docs.
Thanks very much in advance.
Amit
Thanks Colin for your response.
I have tried this script on InDesign CC2018 but did not happen anything after triggered the script.
Amit
If i understand correctly you want to include names that can contain space and - as well, for that you will have to change the grep expression. Change it to the following
"\\b([A-Za-z0-9_ \\-]+\\.ai|[0-9A-Za-z_ \\-]+\\.eps)\\b"
Thank you, Manan.
It works flawlessly. Undoubtedly you are rock mate.
Thanks again for this tremendous script.
Now there is no question regarding this topic. It is obviously close now.
Regards,
Amit
Copy link to clipboard
Copied
Here is a simple AppleScript that can get you started. Note that the regular expression (grep) only allows regular characters and an underscore. Spaces or special characters will require a more robust expression.
--simple regEx expression will not work if spaces, hyphens or special characters allowed in filenames
set findStr to "\\b([A-Za-z0-9_]+\\.ai|[0-9A-Za-z_]+\\.eps)\\b"
--define path to folder of graphics
set fileDest to path to desktop from user domain as string
set folderDest to fileDest & "graphics"
tell application "Adobe InDesign CC 2018"
--simple fine grep
set find grep preferences to nothing
set find what of find grep preferences to findStr
--define find change grep options here
tell find change grep options
set include hidden layers to true
set include locked layers for find to true
end tell
set docRef to document 1
set theStory to story 1 of docRef
tell theStory
set foundList to find grep
end tell
set testList to {}
if length of foundList > 0 then
set find grep preferences to nothing
set testList to {}
with timeout of 300 seconds
repeat with i from length of foundList to 1 by -1
set thisItem to item i of foundList
try
set filePath to (folderDest & ":" & contents of thisItem)
set fileRef to filePath as alias
tell insertion point 1 of thisItem
place fileRef
end tell
on error
set end of testList to filePath
end try
end repeat
end timeout
--return to default
set find grep preferences to nothing
end if
end tell
{foundList, testList}
Copy link to clipboard
Copied
Hi Hopkins,
Thanks for your reply and sorry to late reply from my side due to on vacation.
This script is not working, I tell you every process which I followed:
Please suggest what need to be done or missing anything.
Thanks in advance.
Copy link to clipboard
Copied
Hi Amit,
I have not tried the AppleScript given by Hopkins, but mentioned below is my take on the problem using Javascript.
function findAndReplace(foldername)
{
app.findGrepPreferences.findWhat = "\\b([A-Za-z0-9_]+\\.ai|[0-9A-Za-z_]+\\.eps)\\b"
var nameList = app.activeDocument.findGrep(true)
for(var i = nameList.length - 1; i >= 0; i--)
{
nameList.insertionPoints.itemByRange(0, nameList.insertionPoints.length - 1).place(foldername + "/" + nameList.contents)
}
app.findGrepPreferences = NothingEnum.nothing;
}
This method wants an argument that is the path of the folder from where it needs to pick up the image files to place. Give it a try and let me know how it goes.
-Manan
Copy link to clipboard
Copied
Hi Manan,
Sorry for late reply and thanks to your response.
Please suggest the path (as well as provide the syntax) because nothing will happen.
Thanks,
Amit
Copy link to clipboard
Copied
Hi Amit,
Could you please be specific on what you did and what results did you see. I am hoping that you know how to execute Javascript in InDesign. You could use ExtendScript Toolkit to run the code. The prerequisites for the code to run successfully would be an open document with some story containing the name of the images with extension .ai and .eps. Also you need to add the code to call the method i gave, by specifying the argument of the path of the folder where the images to be placed are present. Something like below
findAndReplace("Path to your folder containing the images to place")
Also make sure that the folder does contain the image with the name that is the same as the text in the document.
-Manan
Copy link to clipboard
Copied
Hi Manan,
Thank you for your reply.
Yes, I know how to execute the JS file because I have many script to short my work.
The Process which I follow as under:
1. copy all text from your script and paste into the extendScript and save the file on respective script folder,
2. put the folder location on line 1 and replace .ai and .eps to jpg and png.
3. run the script and found the error as attached screenshot.
4. file location as attached screenshot.
Please help and let me know if I missed anything.
Regards,
Amit
Copy link to clipboard
Copied
The code is wrong typed, you are never calling the method and also in place of an argument you are sending in a string constant. In order to fix this copy the code i wrote as it is and then at the last add the following line,
findAndReplace("~/Desktop/test")
So the code i gave before is the function definition which describes what the function does, and this line i mentioned above calls this function with an argument. Try this and let me know what you get.
-Manan
Copy link to clipboard
Copied
Hi Manan,
Thanks for your help.
I have copied your text and put on 1st line as below:
and found error as below:
Please suggest.
Regards,
Amit
Copy link to clipboard
Copied
Amit,
How is this screenshot different from the screenshot you pasted before, both have the same code in the first line and also error you get is same. What i am saying is that copy the code i gave before as is without any modification, and then after that add the function call line i.e findAndReplace("~/Desktop/test")
Reading a bit on method calls in JS will help you understand
-Manan
Copy link to clipboard
Copied
Hi Manan,
Thanks for your reply.
I have copied the text in 1st line function findAndReplace("~/Desktop/test") and the error showed.
Then replaced above text with findAndReplace("~/Desktop/test") and the error showed differently.
can you please help me out here step by step, if possible. It really a help me a lot.
Regards,
Amit
Copy link to clipboard
Copied
This is getting really confusing, seems i am creating more confusion then clarity. Lets start over, create a new script and paste the following and run. Then tell what happens
function findAndReplace(foldername)
{
app.findGrepPreferences.findWhat = "\\b([A-Za-z0-9_]+\\.ai|[0-9A-Za-z_]+\\.eps)\\b"
var nameList = app.activeDocument.findGrep(true)
for(var i = nameList.length - 1; i >= 0; i--)
{
nameList[i].place(foldername + "/" + nameList.contents)
}
app.findGrepPreferences = NothingEnum.nothing;
}
findAndReplace("~/Desktop/test")
-Manan
Copy link to clipboard
Copied
Hi Manan,
Here is the snapshot of error:
Copy link to clipboard
Copied
Change the line no 7 to the following and then try
nameList.insertionPoints.itemByRange(0, nameList.insertionPoints.length - 1).place(File(foldername + "/" + nameList.contents))
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Check if the file is present at the location or not? The error specifies the location at which the script is looking for female.eps file
Copy link to clipboard
Copied
only replaced female.eps as screenshot.
rest of the images as is.
Copy link to clipboard
Copied
Is this the result of my code, send me the document and i will have a look at it.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Works for me, have a look at the following GIF
P.S. :- Ignore the prompt that is something not related.
-Manan
Copy link to clipboard
Copied
Hi Manan,
I am working with CC2018, is there problem with InDesign version?
I am enclosed the screenshot attached again what is happened here.
Triggered the script then show the error.
Then placed the irrespective images
What is the behind the reason, its work with you perfectly, not mine.
Copy link to clipboard
Copied
Change the line no 5 with for loop with the following and then try
for(var i = 0; i < nameList.length; i++)
Copy link to clipboard
Copied
Now, its replaced all the text with the below images
adult.eps
cc.eps
female.eps
male.eps
maternity.eps
mcc.eps
newborn.eps
p.eps
pdx.eps
But when I placed whole image list containing with _ - space, it shows the error.
Copy link to clipboard
Copied
Hi Manan,
You are very close to resolving this problem if there is no issue with the file naming.
You are really a very helpful guy, appreciated!!
Please put some effort on this, I hope we will get the positive result.
Regards,
Amit
Copy link to clipboard
Copied
If i understand correctly you want to include names that can contain space and - as well, for that you will have to change the grep expression. Change it to the following
"\\b([A-Za-z0-9_ \\-]+\\.ai|[0-9A-Za-z_ \\-]+\\.eps)\\b"