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

How to count objects

New Here ,
Nov 23, 2023 Nov 23, 2023

Hi communitiy,

 

there's a function in Illustrator named Dokumenteninformation (probably document information) where you can choose objects and receive the object count of selected objects. 

Does InDesign has the same function but with a different name? I've been searching it for quite a while now 😄
Otherwise I need to count roughly 200 squares in my document.... XD

 

Does anyone has a hint? Thanks a lot!

TOPICS
Feature request , How to
2.7K
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 ,
Nov 24, 2023 Nov 24, 2023

Oh no I read it wrong 

function countObjectsOnPage(page) {
    return page.allPageItems.length;
}

function countObjectsOnSpecifiedPages(pageNumbers) {
    var totalObjects = 0;
    var doc = app.activeDocument;

    var pageList = pageNumbers.split(',');
    for (var i = 0; i < pageList.length; i++) {
        var range = pageList[i].replace(/^\s+|\s+$/g, '').split('-');  // Trim whitespace

        if (range.length === 1) {
            var pageNumber = parseInt(range[0]);
            var page = doc.pages.item(pageNumber - 1);

            if (page) {
                totalObjects += countObjectsOnPage(page);
            } else {
                $.writeln("Invalid page number: " + pageNumber);
            }
        } else if (range.length === 2) {
            // Page range
            var startPage = parseInt(range[0]);
            var endPage = parseInt(range[1]);

            for (var j = startPage; j <= endPage; j++) {
                var page = doc.pages.item(j - 1);

                if (page) {
                    totalObjects += countObjectsOnPage(page);
                } else {
                    $.writeln("Invalid page number in range: " + j);
                }
            }
        }
    }

    return totalObjects;
}

function main() {
    var doc = app.activeDocument;

    var pageNumbers = prompt("Enter page numbers (e.g., 1-3, 5, 7):", "1-3, 5, 7");

    if (pageNumbers) {
        alert("Total number of objects on specified pages: " + countObjectsOnSpecifiedPages(pageNumbers));
    } else {
        alert("Invalid input");
    }
}

main();



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 ,
Nov 24, 2023 Nov 24, 2023
LATEST

This one counts selected objects

function countSelectedObjects() {
    var selectedItems = app.activeDocument.selection;
    if (selectedItems && selectedItems.length > 0) {
        return selectedItems.length;
    } else {
        return 0;
    }
}

function main() {
    var selectedCount = countSelectedObjects();
    alert("Number of selected objects: " + selectedCount);
}

main();
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