Copy link to clipboard
Copied
Hi, I am looking for a script, that automatically replaces a placeholder paragraph with the appropriate inline image in the same postion. The image should be identified by the paragraph text (could be URL, ID, Name, etc.) I would use a paragraph style that only serves that purpose. There are multiple positions in the body copy that would need this replacement. All images will have the same width but potentially different heights. All instances are in one linked textframe spread across multiple pages. Using a placeholder/url relative to the path of the .indd file would be my preferred way to use this.
1. Scan selected textframe for first instance (solved)
2. Disect the URL from selected text (solved)
3. Delete selected text and place inline image from created URL instead (solved)
4. Scale image to set width
5. Repeat for all instances (solved)
Thanks for any help.
EDIT:
I did come across a solution for a part of my problem now. I don't know why I couldn't find it before.
main();
function main()
{
var doc = app.activeDocument;
if(app.documents.length > 0)
{
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
replaceImage("^.*\.png");
}
else { alert("No document opened!"); }
}
function replaceImage(query)
{
// Clean the pre-existing GREP and add our query
app.findGrepPreferences.findWhat = query;
var result = app.findGrep();
var folder = 'C:/*****/images/';
// Look for each result of the GREP query and replace it by the image.
for (var i = result.length-1; i > 0; i--)
{
var imageName = result[i].contents;
var imagePath = folder+imageName;
// Place the image in the found text
result[i].insertionPoints[0].place(imagePath);
// Delete the text
result[i].remove();
}
}
Copy link to clipboard
Copied
Set a variable at your .place function: var placedImg = results[i].place(imagePath);
Then, you can access the image and use the resize method with: placedImg[0].resize(args);
For more on resize: https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Image.html#d1e236446__d1e239706
Copy link to clipboard
Copied
This script is placing also inline images.
But the placeholder needs to be marked with a hashtag (e.g ##imageName.pd##)
http://www.indesignscript.de/skript-detail/detail/News/snippetplacer/