Copy link to clipboard
Copied
I've written a script that provides a page and table count for each document and a total for a book. I also want a count of all figures in each document. I tried the following, but counting graphic objects gives me a count that is many times more than the number of figures in the document.
function countFigures() {
figureCtr = 0;
var figure = doc.FirstGraphicInDoc;
while (figure.ObjectValid()) {
figureCtr++;
figure = figure.NextGraphicInDoc;
}
return figureCtr;
}
I've searched the forum for other examples, without success. We work with relatively large books and these totals are useful in assessing the level of effort for each book.
Many thanks in advance...
There are many different Graphic objects, including TextFrame, Line, Rectangle, etc. objects. So you have to test what kind you are looking for. If you want imported graphics, you look for Inset objects:
if (figure.constructor.name === "Inset") {
// Imported graphic.
}
I was logged in with a beta login and it gave me the magnicent_warmth handle. I want credit for the correct answer lol.
There are many different Graphic objects, including TextFrame, Line, Rectangle, etc. objects. So you have to test what kind you are looking for.
if (figure.constructor.name === "Inset") {
// Imported graphic.
}
else if (figure.constructor.name === "AFrame") {
// Anchored frame.
}
Figure, as opposed to Object, is an authoring-level page layout concept, typically a floating block of some sort.
In FM, a single figure might be one Anchored Frame containing multiple imported objects.
So an algorithm that enumerates imported objects might find that total to be different from the count of AFs. And for extra confusion, an AF can be empty (used to shove other content around, for example), and an import might be on a Master Page.
This might or might not matter in your context.
Hi,
You could also count the number of figure tables (if you put your figures into tables) or the number of figure title paragraphs.
Anchored frames can also be used for warning icons, etc. I do not know, if you want to count these as well.
Best regards, Winfried
Thanks! One thing to be aware of with loops like this: they traverse every object in the document, including thos on Master and Reference pages. So your "extra" frame may be on one of those pages.
Copy link to clipboard
Copied
There are many different Graphic objects, including TextFrame, Line, Rectangle, etc. objects. So you have to test what kind you are looking for. If you want imported graphics, you look for Inset objects:
if (figure.constructor.name === "Inset") {
// Imported graphic.
}
Copy link to clipboard
Copied
I was logged in with a beta login and it gave me the magnicent_warmth handle. I want credit for the correct answer lol.
There are many different Graphic objects, including TextFrame, Line, Rectangle, etc. objects. So you have to test what kind you are looking for.
if (figure.constructor.name === "Inset") {
// Imported graphic.
}
else if (figure.constructor.name === "AFrame") {
// Anchored frame.
}
Copy link to clipboard
Copied
"magnificent_warmth" surprised me! Happy you cleared that up. Both answers were spot on...credit where credit is due! Turns out our figures use the "AFrame" constructor.name. There's one other graphic object that is assigned the AFrame name occasionally; e.g., two times in a 500-page document. Maybe an old figure was deleted, but the frame still exists. Either way, I can live with that.
Hope all is going well and you got to enjoy the Easter season.
Copy link to clipboard
Copied
Thanks! One thing to be aware of with loops like this: they traverse every object in the document, including thos on Master and Reference pages. So your "extra" frame may be on one of those pages.
Copy link to clipboard
Copied
Lol - I thought "magnicent_warmth" was sounding a lot like you Rick!
Copy link to clipboard
Copied
Thank you @magnificent_warmth6396 , for all you do! 🙂
Copy link to clipboard
Copied
Figure, as opposed to Object, is an authoring-level page layout concept, typically a floating block of some sort.
In FM, a single figure might be one Anchored Frame containing multiple imported objects.
So an algorithm that enumerates imported objects might find that total to be different from the count of AFs. And for extra confusion, an AF can be empty (used to shove other content around, for example), and an import might be on a Master Page.
This might or might not matter in your context.
Copy link to clipboard
Copied
Hi,
You could also count the number of figure tables (if you put your figures into tables) or the number of figure title paragraphs.
Anchored frames can also be used for warning icons, etc. I do not know, if you want to count these as well.
Best regards, Winfried
Copy link to clipboard
Copied
Now I see why it's so difficult (confusing) to count figures. Unfortunately, I don't have any say over how the customer does their figures, but since they all appear to be AFrame, helps to narrow the search. Am going to be out of town for a month (travel), but will take all your advice and see if I can track down the two extra figures in the one chapter when I get back. Good news is it's a small chapter.
Again, my deepest appreciation to everyone on the forum for all the great support!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now