Copy link to clipboard
Copied
I just checked the API documentation and didn’t see anything on point about this.
Is it possible to write a script that applies an existing Object Style to an inline jpg image based on the Paragraph Style applied to that inline jpg image?
Hi,
I did it in the following way:
...var curDoc = app.activeDocument;
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat= "~a";
var allFounds = curDoc.findGrep();
for (var i = 0; i < allFounds.length; i++) {
var curFound = allFounds;
if (curFound.allGraphics.length > 0) {
var pStyleName = curFound.paragraphs[0].appliedParagraphStyle.name;
if (pStyleName == "paraStyle") {
var rect = curFound.rectangles[0];
rect.appliedObjectStyle = curDoc.object
Copy link to clipboard
Copied
Yes, this is possible:
1. Search a anchored object with '~a'
2. Loop through all founds
3. Check if the current found has a graphic
4. Check the applied paragraph style of the corresponding paragraph
5. If there is a match, choose the rectangle and apply your object style.
Kai
Copy link to clipboard
Copied
Thank you.
Copy link to clipboard
Copied
Kai,
I’m stuck on figuring out how to “choose the rectangle”. Once you’ve found an anchored object with appliedParagraphStyle, how do you select the object contained in the anchor marker so that you can applyObjectStyle?
Copy link to clipboard
Copied
Hi,
I did it in the following way:
var curDoc = app.activeDocument;
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat= "~a";
var allFounds = curDoc.findGrep();
for (var i = 0; i < allFounds.length; i++) {
var curFound = allFounds;
if (curFound.allGraphics.length > 0) {
var pStyleName = curFound.paragraphs[0].appliedParagraphStyle.name;
if (pStyleName == "paraStyle") {
var rect = curFound.rectangles[0];
rect.appliedObjectStyle = curDoc.objectStyles.itemByName("myStyle");
}
}
}
Kai
Copy link to clipboard
Copied
Kai,
The documentation on Rectangles was unclear to me, so I was trying to come at it using PageItem. Your code is perfectly clear. Thank you.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now