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

Get paragraphs with anchored images

Guest
Aug 26, 2017 Aug 26, 2017

Hello

I have a Text frame with several paragraphs and several inline images between them. I mean with inline images those that are anchored to the paragraphs using the place method.

I want to know to get those paragraphs that have anchored images, something like myAnchoredImage.parentParagraph o so.

I have found some examples about how to place or move an object to a determined paragraphs using the AnchoredObjectSetting property using some insertionPoint as destination. But I still dont know how to do the reverse operation.

Please any help.

Thanks in advance.

TOPICS
Scripting
1.3K
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
Mentor ,
Aug 27, 2017 Aug 27, 2017

Hi,

Starting from a 'Story' - use:

myStory.splineItems;

to get a collections of anchored graphicFrames like 'rectangles', 'ovals', polygons', an so on.

(you can start from selection, textFrame etc.)

Each one's parent is 'character'. This character.paragraphs[0] is a ''wanted' paragraph.

Jarek

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
LEGEND ,
Aug 27, 2017 Aug 27, 2017

Hi Jarek,

If I've understood well, it's more clever to use "splineItems" to directly find all "inline" graphic frames than play with a Grep F/R that will catch all "~a", and so text frames too!

Right? …

(^/)

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
Mentor ,
Aug 27, 2017 Aug 27, 2017

Hi,

Both ways are clever enough,  I guess

Crucial is the goal you want to reach. So if we are hunting for images splineItems leads us a step further.

Jarek

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
LEGEND ,
Aug 27, 2017 Aug 27, 2017

… Could we directly get an array of splineItems containing is an image [… without playing a loop]? 

Thanks in advance!

(^/)

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
Mentor ,
Aug 27, 2017 Aug 27, 2017

Hi,

text.splineItems.everyItem().graphics.everyItem().getElements();

returns an array with graphics from anchored graphicFrames (empty ignored).

Each element parent.parent.paragraphs[0] is "wanted" paragraph.

(more or less - notice i.e. groups)

Jarek

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
LEGEND ,
Aug 27, 2017 Aug 27, 2017

Merci, Jarek

(^/)

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 28, 2017 Aug 28, 2017

https://forums.adobe.com/people/Obi-wan+Kenobi  wrote

… Could we directly get an array of splineItems containing is an image [… without playing a loop]? 

Hi Obi-wan,

Jarek answered that indirectly. Without doing a loop through the found graphics? No.
And if the found graphics are images we can only tell after asking when doing the loop.

About the wanted paragraphs:

Indeed the parent.parent of a found graphic in Jarek's scenario is a character.

And parent.parent.paragraphs[0] is the desired paragraph.

I see no group object, because splineItems are by definition graphicLines, polygons, ovals and rectangles.

If we have to deal with anchored groups containing graphics or other nested structures that can contain graphics we need a different concept to detect the graphics.

text.splineItems.everyItem().allGraphics;

or:

text.allGraphics;

In that last line even an anchored text frame with an anchored graphic will be listed in the result array.

EDIT: I should have said:
In the last line even the graphic that is anchored in an anchored text frame will be listed in the result array.

So for that we need a detection mechanism to go back to the story where we want to get the paragraph from.

Regards,
Uwe

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
LEGEND ,
Aug 28, 2017 Aug 28, 2017

Hi Uwe & Jarek,

What I mean is about different ways to get the same result!

These 3 writings seem to be equivalent:

var myDoc = app.activeDocument; 

app.findGrepPreferences = null;

app.findGrepPreferences.findWhat = "~a";

myInlines = myDoc.findGrep();

var I = myInlines.length;

for ( var i = 0; i < I; i++ ) (myInlines.splineItems[0].isValid) && (myInlines.splineItems[0].allGraphics.length != 0) && (myInlines.splineItems[0].parent.paragraphs[0].appliedParagraphStyle = "Blue") && (myInlines.pageItems[0].applyObjectStyle(myDoc.objectStyles.item("Red")));

app.findGrepPreferences = null;

var myDoc = app.activeDocument,

myInlines = myDoc.stories.everyItem().splineItems.everyItem().getElements(),

I = myInlines.length;

for ( var i = 0; i < I; i++ ) (myInlines.allGraphics.length != 0) && (myInlines.parent.paragraphs[0].appliedParagraphStyle = "Blue") && (myInlines.applyObjectStyle(myDoc.objectStyles.item("Red")));

var myDoc = app.activeDocument,

myInlinesGraphics = myDoc.stories.everyItem().splineItems.everyItem().graphics.everyItem().getElements(),

I = myInlinesGraphics.length;

for ( var i = 0; i < I; i++ ) (myInlinesGraphics.parent.parent.paragraphs[0].appliedParagraphStyle = "Blue") && (myInlinesGraphics.parent.applyObjectStyle(myDoc.objectStyles.item("Red")));

… but could the 3rd script be faster?! 

(^/)

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
Guest
Sep 09, 2017 Sep 09, 2017
LATEST

Thanks to all of you, guys. I was using myStory.rectangles but I didnt realize that the myParagraphs.rectangles is also posible to get the anchored images.

Now I can find the wanted paragraph although to get their absolute index I must make a loop thru all paragraphs of the Story. I think there's no way to get it directly. Maybe I should change the algorithm to pass that problem.

The good is that my project works pretty good.

Again, thank you very much.

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
Guest
Sep 09, 2017 Sep 09, 2017

Im using myParagraphs[index].rectangles with filtering thru a previously inserted label.

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