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

How to capture images contained in text selections and apply object styles to the images?

Guide ,
Aug 11, 2025 Aug 11, 2025

I have selected some text, tables, and images, and I want to apply object styles(exapmle name:"AA") to the images.
How do I capture these images?
Sometimes they are imported from Word without links. Other times, they may be linked.

 

This is the original code for capturing the table:

       if (app.selection != null) {
            for (var f = 0; f < app.selection.length; f++) {
                var obj = app.selection[f];
                var t = obj.texts[0].tables;
. . . 

}

 

TOPICS
How to , Scripting
244
Translate
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 , Aug 11, 2025 Aug 11, 2025
//a selection’s graphics as an array
var sg = app.selection[0].allGraphics
alert("There are " + sg.length + " graphics in the selection")
if (sg != null) {
    for (var f = 0; f < sg.length; f++) {
        sg[f].appliedObjectStyle = app.activeDocument.objectStyles.itemByName("AA");
    }
}

 

Screen Shot.png

Screen Shot 1.png

 

Translate
Community Expert ,
Aug 11, 2025 Aug 11, 2025
//a selection’s graphics as an array
var sg = app.selection[0].allGraphics
alert("There are " + sg.length + " graphics in the selection")
if (sg != null) {
    for (var f = 0; f < sg.length; f++) {
        sg[f].appliedObjectStyle = app.activeDocument.objectStyles.itemByName("AA");
    }
}

 

Screen Shot.png

Screen Shot 1.png

 

Translate
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
Guide ,
Aug 11, 2025 Aug 11, 2025

Hi rob day.

Thank you very much.

It seems that the object style has not been applied successfully.

 

I saw it.

It seems that the white arrow is the only one that shows the effect?

 

Translate
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 ,
Aug 11, 2025 Aug 11, 2025

It seems that the object style has not been applied successfully.

 

It is in my example—it’s been set to your AA object style.

 

Note that it has to be:

 

sg[f].appliedObjectStyle = app.activeDocument.objectStyles.itemByName("AA");
 
A string like this doesn’t work
sg[f].appliedObjectStyle = "AA";
Translate
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
Guide ,
Aug 11, 2025 Aug 11, 2025

Clear object style priority. Is there any other code?
I don't know if this works.

sg[f].clearObjectStyleOverrides()

 

 I've always wanted to ask, I can't manually clear the “+” on object style AA.
Even when I press the Alt key.

Translate
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
Guide ,
Aug 11, 2025 Aug 11, 2025

Is it possible to clear the object style priority?
This does not seem to work for object styles.

Even if I set it in the object style, the frame does not seem to be removed.
I may need to add FRAME_TO_CONTENT.

 

dublove_0-1754925238056.jpeg

 

Translate
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 ,
Aug 11, 2025 Aug 11, 2025

I don’t understand, when I apply the style to your sample with my script I get this

 

Screen Shot 4.png

Translate
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
Guide ,
Aug 11, 2025 Aug 11, 2025

I set AA.
Proportionally fit content. Size is 42mm.

Translate
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
Guide ,
Aug 11, 2025 Aug 11, 2025

Thank you

Translate
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
Guide ,
Aug 13, 2025 Aug 13, 2025
LATEST

Hi rob day.

How can I capture an image when no object is selected?
It seemed to work fine before.
It's just that alert(g.length) seems to be wrong.

alert(g); and alert(g.length); seem to have different quantities.

alert(g); resut is this:

dublove_0-1755080612524.jpeg

 

but alert(g.length); resut is 2. 

 
g[f].clearObjectStyleOverrides(); will also cause an error.
It seems that g[f] does not exist?

 

function noSelect() {
    var myDocument = app.documents.item(0);
    var myStory = myDocument.stories;
    var p = myStory.everyItem().paragraphs.everyItem();
    var c = myStory.everyItem().tables.everyItem().cells;
    var t = myStory.everyItem().tables;
    var g = myStory.everyItem().allGraphics;
    alert(g);
    alert(g.length);
    for (var s = 0; s < myStory.length; s++) {
...

        if (g != null) {
            for (var f = 0; f < g.length; f++) {
                g[f].clearObjectStyleOverrides();
                g[f].parent.appliedObjectStyle = app.activeDocument.objectStyles.itemByName(initImObjStn);
                g[f].fit(FitOptions.FRAME_TO_CONTENT);
            }
        }

 

Translate
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