Skip to main content
dublove
Legend
Aug 11, 2025 11:22 AM UTC
Answered

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

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;
. . . 

}

 

rob day
rob dayCorrect answer
Community Expert
Aug 11, 2025 2:29 PM UTC
//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");
    }
}

 

 

9 replies

rob day
Community Expert
rob dayCommunity ExpertCorrect answer
Community Expert
Aug 11, 2025 2:29 PM UTC
//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");
    }
}

 

 

Translate
dublove
dubloveAuthor
Legend
Aug 11, 2025 3:01 PM UTC

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
rob day
Community Expert
Community Expert
Aug 11, 2025 3:10 PM UTC

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