Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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? …
(^/)
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
… Could we directly get an array of splineItems containing is an image [… without playing a loop]?
Thanks in advance!
(^/)
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Merci, Jarek
(^/)
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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?!
(^/)
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Im using myParagraphs[index].rectangles with filtering thru a previously inserted label.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now