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

Loop through inline images - anchored objects and ap[ply object style, script or GREP?

Explorer ,
Mar 15, 2022 Mar 15, 2022

Copy link to clipboard

Copied

I am reworking many documents that have icons at the start of most paragraphs. There can be anywhere from 1 to 4 icons and I need to apply an object style for positioning to each one.

 

Is there a quicker way, either with GREP or a script to achieve this? 

 

Object style.png

 

Thanks for any help,

Randy

TOPICS
Scripting

Views

237

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
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 15, 2022 Mar 15, 2022

Maybe something like this?

var ostyles = [
    "1-1e picto",
    "2-2e picto",
    "3-3e picto",
    "4-4e picto"
];

var allPars = app.activeDocument.stories.everyItem().paragraphs.everyItem().getElements();
var ostyleCol = app.activeDocument.objectStyles;
var allAnchs, i, a;
for (i = 0; i < allPars.length; i++) {
    allAnchs = allPars[i].pageItems;
    for (a = 0; a < allAnchs.length; a++) { 
        try { allAnchs[a].applyObjectStyle(ostyleCol.itemByName(ostyles[a])); }
        catch(e) { }
...

Likes

Translate

Translate
Community Expert ,
Mar 15, 2022 Mar 15, 2022

Copy link to clipboard

Copied

The same object style to all inlines?

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
community guidelines
Explorer ,
Mar 15, 2022 Mar 15, 2022

Copy link to clipboard

Copied

Hi,

 

No if only one icon it will have the same, second thwe same etc. This is for positioning only once I apply paragraph styles with numbering. 

 

I did have a grep to select each one on another computer a few weeks ago but work deleted that copy of InDesign so I cannot figure out what I did with GREP. It was quicker than selecting and changing the object style.

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
community guidelines
Community Expert ,
Mar 15, 2022 Mar 15, 2022

Copy link to clipboard

Copied

Maybe something like this?

var ostyles = [
    "1-1e picto",
    "2-2e picto",
    "3-3e picto",
    "4-4e picto"
];

var allPars = app.activeDocument.stories.everyItem().paragraphs.everyItem().getElements();
var ostyleCol = app.activeDocument.objectStyles;
var allAnchs, i, a;
for (i = 0; i < allPars.length; i++) {
    allAnchs = allPars[i].pageItems;
    for (a = 0; a < allAnchs.length; a++) { 
        try { allAnchs[a].applyObjectStyle(ostyleCol.itemByName(ostyles[a])); }
        catch(e) { }
    }
}

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
community guidelines
Explorer ,
Mar 15, 2022 Mar 15, 2022

Copy link to clipboard

Copied

Thanks,

 

I will check it out later and let you know. I am just downloading Visual Studio Code here on my Windows machine. This looks like JavaScript, I presume this is the best cross-platform language for InDesign?

 

I am more of a designer than a programmer but I did do some simple python when working with Rhino3D. I am just getting back into InDesign. 

 

Thanks, looking forward to learning more scripting here.

Randy

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
community guidelines
Community Expert ,
Mar 15, 2022 Mar 15, 2022

Copy link to clipboard

Copied

This is Extendscript, which is basically Adobe's (ancient) flavor of Javascript. It can be edited with any plain text editor, including VSC. For instructions on how to install it in InDesign, see: https://creativepro.com/how-to-install-a-script-in-indesign-that-you-found-in-a-forum-or-blog-post/

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
community guidelines
Explorer ,
Mar 15, 2022 Mar 15, 2022

Copy link to clipboard

Copied

I just got the ExtendScript debugger for VS Code. Thanks again. 

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
community guidelines
Community Expert ,
Mar 15, 2022 Mar 15, 2022

Copy link to clipboard

Copied

This is a very helpful resource for understanding the InDesign DOM if you'd like to delve deeper into scripting: https://www.indesignjs.de/extendscriptAPI/indesign-latest/#about.html

 

Glad I could help. 

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
community guidelines
Explorer ,
Mar 15, 2022 Mar 15, 2022

Copy link to clipboard

Copied

Excellent, I just set up a copy document and ran the script and it is perfe3ct. 

 

This will help me learn. Very much appreciated.

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
community guidelines
Community Expert ,
Mar 15, 2022 Mar 15, 2022

Copy link to clipboard

Copied

"I just got the ExtendScript debugger for VS Code. Thanks again. "

 

Hi Randy,

because you are on Windows you still can use the ExtendScript Toolkit app (ESTK) if you prefer this as your development tool. That's the "old" tool for developing ExtendScript scripts for InDesign, Illustrator and e.g. PhotoShop on Windows and older versions of Mac OS X as well. Just in case, you still can download and install the ESTK on a current Windows 10 machine, even on Windows 11, I think.

 

Scroll down to the installer links:

https://prodesigntools.com/adobe-cc-direct-download-links.html

Also see into this:

https://extendscript.docsforadobe.dev/extendscript-toolkit/index.html

https://extendscript.docsforadobe.dev/extendscript-toolkit/configuring-the-toolkit-window.html

https://extendscript.docsforadobe.dev/extendscript-toolkit/debugging-in-the-toolkit.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
community guidelines
Explorer ,
Mar 16, 2022 Mar 16, 2022

Copy link to clipboard

Copied

LATEST

Thanks Uwe,

 

I will look at that. 

 

Best Regards,

Randy

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
community guidelines