Highlighted

Can you convert the text in word into a path and insert the picture?

Explorer ,
Nov 01, 2020

Copy link to clipboard

Copied

There are a lot of illustrations in word, and it is difficult to find the position if they are to be included in InDesign.
Is there a way to directly convert some specific text in word into the path of the picture and insert it?
For example, there is a text like this:
-------------------------------------------------- --------------------------------------------------
In the United States, which is mired in multiple crises such as the new crown epidemic, economic recession, and racial issues, political polarization and social division have worsened during the election year, with frequent demonstrations, protests, conflicts, and riots.
@ D:\Mybook\abc\001. election.PSD@@
Election day on November 3 is imminent, and general election-related disputes such as mail voting may add another "fuse." American scholar Francis Fukuyama recently wrote an article worrying that "the United States may be experiencing a major crisis related to the election itself."
-------------------------------------------------- --------------------------------------------------

Can the picture pointed to by @ D:\Mybook\abc\001. election.PSD@ be inserted into this position automatically?

If it can be realized, multi-picture typesetting would be too much trouble...

Adobe Community Professional
Correct answer by Sunil Yadav | Adobe Community Professional

Try this code sample:

//////////////////////////////////////////////////////////////////////////////////////////////////////
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = "(?<=@)([^@]+)(?=@)";
var allFound = app.documents[0].findGrep();
for(var i = 0; i < allFound.length; i){
    var allContent = allFound[i].texts[0].contents;
    var filePath = File(allContent.toString().replace(/[\s]+/g,'').replace(/\\/g,'/'));
    if(filePath.exists){
        if(allFound[i].insertionPoints[0].parent.characters[allFound[i].texts[0].characters[-1].index+1].contents == "@"){
            allFound[i].insertionPoints[0].parent.characters[allFound[i].texts[0].characters[-1].index+1].contents = "";
            app.documents[0].recompose();
            }
        allFound[i].texts[0].contents = "";
        allFound[i].texts[0].insertionPoints[0].place(filePath);
        if(allFound[i].insertionPoints[0].parent.characters[allFound[i].texts[0].characters[0].index-1].contents == "@"){
            allFound[i].insertionPoints[0].parent.characters[allFound[i].texts[0].characters[0].index-1].contents = "";
            app.documents[0].recompose();
            }
        }
    else{
        i++;
        }
    app.documents[0].recompose();
    var allFound = app.documents[0].findGrep();
    }

//////////////////////////////////////////////////////////////////////////////////////////////////////

Best

Sunil

TOPICS
Bug, Feature request, How to, Import and export, Scripting, Server developers

Views

62

Likes

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

Can you convert the text in word into a path and insert the picture?

Explorer ,
Nov 01, 2020

Copy link to clipboard

Copied

There are a lot of illustrations in word, and it is difficult to find the position if they are to be included in InDesign.
Is there a way to directly convert some specific text in word into the path of the picture and insert it?
For example, there is a text like this:
-------------------------------------------------- --------------------------------------------------
In the United States, which is mired in multiple crises such as the new crown epidemic, economic recession, and racial issues, political polarization and social division have worsened during the election year, with frequent demonstrations, protests, conflicts, and riots.
@ D:\Mybook\abc\001. election.PSD@@
Election day on November 3 is imminent, and general election-related disputes such as mail voting may add another "fuse." American scholar Francis Fukuyama recently wrote an article worrying that "the United States may be experiencing a major crisis related to the election itself."
-------------------------------------------------- --------------------------------------------------

Can the picture pointed to by @ D:\Mybook\abc\001. election.PSD@ be inserted into this position automatically?

If it can be realized, multi-picture typesetting would be too much trouble...

Adobe Community Professional
Correct answer by Sunil Yadav | Adobe Community Professional

Try this code sample:

//////////////////////////////////////////////////////////////////////////////////////////////////////
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = "(?<=@)([^@]+)(?=@)";
var allFound = app.documents[0].findGrep();
for(var i = 0; i < allFound.length; i){
    var allContent = allFound[i].texts[0].contents;
    var filePath = File(allContent.toString().replace(/[\s]+/g,'').replace(/\\/g,'/'));
    if(filePath.exists){
        if(allFound[i].insertionPoints[0].parent.characters[allFound[i].texts[0].characters[-1].index+1].contents == "@"){
            allFound[i].insertionPoints[0].parent.characters[allFound[i].texts[0].characters[-1].index+1].contents = "";
            app.documents[0].recompose();
            }
        allFound[i].texts[0].contents = "";
        allFound[i].texts[0].insertionPoints[0].place(filePath);
        if(allFound[i].insertionPoints[0].parent.characters[allFound[i].texts[0].characters[0].index-1].contents == "@"){
            allFound[i].insertionPoints[0].parent.characters[allFound[i].texts[0].characters[0].index-1].contents = "";
            app.documents[0].recompose();
            }
        }
    else{
        i++;
        }
    app.documents[0].recompose();
    var allFound = app.documents[0].findGrep();
    }

//////////////////////////////////////////////////////////////////////////////////////////////////////

Best

Sunil

TOPICS
Bug, Feature request, How to, Import and export, Scripting, Server developers

Views

63

Likes

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
Nov 01, 2020 0
Adobe Community Professional ,
Nov 01, 2020

Copy link to clipboard

Copied

Perhaps with scripting (but I'm not a script writer). Definitely it's not built into InDesign's native abilities.

 

Likes

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
Reply
Loading...
Nov 01, 2020 0
Adobe Community Professional ,
Nov 02, 2020

Copy link to clipboard

Copied

Hi,

it seems that a script originally written by Peter Kahrel and adapted by Kasyan Servetsky could do what you want:

 

Place inline images

Script for InDesign: tested in CC 2015.4

This script It finds text between two @ characters – e.g. @pencil.tif@ – and replaces it with the image that has the same name. The original script was written by Peter Kahrel. I found it somewhere on the Adobe scripting forum and reworked it to my liking.

http://kasyan.ho.ua/indesign/image/place_inline_images.html

 

Regards,
Uwe Laubender

( ACP )

Likes

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
Reply
Loading...
Nov 02, 2020 0
Adobe Community Professional ,
Nov 02, 2020

Copy link to clipboard

Copied

Try this code sample:

//////////////////////////////////////////////////////////////////////////////////////////////////////
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = "(?<=@)([^@]+)(?=@)";
var allFound = app.documents[0].findGrep();
for(var i = 0; i < allFound.length; i){
    var allContent = allFound[i].texts[0].contents;
    var filePath = File(allContent.toString().replace(/[\s]+/g,'').replace(/\\/g,'/'));
    if(filePath.exists){
        if(allFound[i].insertionPoints[0].parent.characters[allFound[i].texts[0].characters[-1].index+1].contents == "@"){
            allFound[i].insertionPoints[0].parent.characters[allFound[i].texts[0].characters[-1].index+1].contents = "";
            app.documents[0].recompose();
            }
        allFound[i].texts[0].contents = "";
        allFound[i].texts[0].insertionPoints[0].place(filePath);
        if(allFound[i].insertionPoints[0].parent.characters[allFound[i].texts[0].characters[0].index-1].contents == "@"){
            allFound[i].insertionPoints[0].parent.characters[allFound[i].texts[0].characters[0].index-1].contents = "";
            app.documents[0].recompose();
            }
        }
    else{
        i++;
        }
    app.documents[0].recompose();
    var allFound = app.documents[0].findGrep();
    }

//////////////////////////////////////////////////////////////////////////////////////////////////////

Best

Sunil

Likes

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
Reply
Loading...
Nov 02, 2020 0