• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Auto Link in InDesign

Participant ,
Oct 18, 2018 Oct 18, 2018

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

TOPICS
Scripting

Views

2.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 3 Correct answers

Participant , Nov 20, 2018 Nov 20, 2018

Thanks Colin for your response.

I have tried this script on InDesign CC2018 but did not happen anything after triggered the script.

Amit

Votes

Translate

Translate
Community Expert , Nov 20, 2018 Nov 20, 2018

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"

Votes

Translate

Translate
Participant , Nov 21, 2018 Nov 21, 2018

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

Votes

Translate

Translate
Enthusiast ,
Oct 19, 2018 Oct 19, 2018

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}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 31, 2018 Oct 31, 2018

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:

  1. Copy the script and paste in to script editor and place on script panel in InDesign. As well as change the file extension in the script.
  2. Place reference text in InDesign document as screenshot attached.
  3. All related images keep on Desktop.
  4. Then run the script and didn't happen anything.

Please suggest what need to be done or missing anything.

Thanks in advance.

Screen Shot 2018-10-31 at 5.22.38 PM.pngScreen Shot 2018-10-31 at 5.22.26 PM.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 01, 2018 Nov 01, 2018

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 06, 2018 Nov 06, 2018

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 06, 2018 Nov 06, 2018

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 12, 2018 Nov 12, 2018

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.

script.png

3. run the script and found the error as attached screenshot.

Screen Shot 2018-11-12 at 3.54.05 PM.png

4. file location as attached screenshot.

desktop.png

Please help and let me know if I missed anything.

Regards,

Amit

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 12, 2018 Nov 12, 2018

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 20, 2018 Nov 20, 2018

Copy link to clipboard

Copied

Hi Manan,

Thanks for your help.

I have copied your text and put on 1st line as below:

Screen Shot 2018-11-20 at 4.26.46 PM.png

and found error as below:

Screen Shot 2018-11-20 at 4.26.15 PM.png

Please suggest.

Regards,

Amit

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 20, 2018 Nov 20, 2018

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 20, 2018 Nov 20, 2018

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.

Screen Shot 2018-11-20 at 5.59.59 PM.png

Then replaced above text with findAndReplace("~/Desktop/test") and the error showed differently.

Screen Shot 2018-11-20 at 6.00.10 PM.png

can you please help me out here step by step, if possible. It really a help me a lot.

Regards,

Amit

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 20, 2018 Nov 20, 2018

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 20, 2018 Nov 20, 2018

Copy link to clipboard

Copied

Hi Manan,

Here is the snapshot of error:

Screen Shot 2018-11-20 at 6.14.53 PM.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 20, 2018 Nov 20, 2018

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))

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 20, 2018 Nov 20, 2018

Copy link to clipboard

Copied

Screen Shot 2018-11-20 at 6.25.48 PM.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 20, 2018 Nov 20, 2018

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 20, 2018 Nov 20, 2018

Copy link to clipboard

Copied

only replaced female.eps as screenshot.

Screen Shot 2018-11-20 at 6.36.13 PM.png

rest of the images as is.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 20, 2018 Nov 20, 2018

Copy link to clipboard

Copied

Is this the result of my code, send me the document and i will have a look at it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 20, 2018 Nov 20, 2018

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 20, 2018 Nov 20, 2018

Copy link to clipboard

Copied

Works for me, have a look at the following GIF

Image_Replace.gif

P.S. :- Ignore the prompt that is something not related.

-Manan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 20, 2018 Nov 20, 2018

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.

Screen Shot 2018-11-20 at 7.28.14 PM.png

Then placed the irrespective images

Screen Shot 2018-11-20 at 7.28.32 PM.png

What is the behind the reason, its work with you perfectly, not mine.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 20, 2018 Nov 20, 2018

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++)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 20, 2018 Nov 20, 2018

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.

Screen Shot 2018-11-20 at 7.57.03 PM.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 20, 2018 Nov 20, 2018

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 20, 2018 Nov 20, 2018

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"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines