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

Graphic Object Style based on Paragraph Style?

Explorer ,
Jun 16, 2016 Jun 16, 2016

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?

TOPICS
Scripting
636
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

Enthusiast , Jun 20, 2016 Jun 20, 2016

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

...
Translate
Enthusiast ,
Jun 17, 2016 Jun 17, 2016

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

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
Explorer ,
Jun 17, 2016 Jun 17, 2016

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
Explorer ,
Jun 20, 2016 Jun 20, 2016

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?

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
Enthusiast ,
Jun 20, 2016 Jun 20, 2016

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

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
Explorer ,
Jun 20, 2016 Jun 20, 2016
LATEST

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.

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