Skip to main content
dublove
Legend
June 18, 2026
Answered

Without 'allObject StyleGroups', cannot traverse all groups?

  • June 18, 2026
  • 3 replies
  • 80 views

There are allOjcetStyles, but there is no 'allObject StyleGroups'.
Is there any way to correct the following code so that it can recognize all situations of groups, including nested groups within groups.

var creGroup = newGroup("myGroup", "objectStyleGroups");
function newGroup(grn, sgc) {
var d = app.activeDocument;
for (var i = 0; i < d[sgc].length; i++) {
if (d[sgc][i].name == grn) {
return true
break
}
}
return d[sgc].add({ name: grn });
}

 

    Correct answer rob day

    Recursive loops are challenging to code. This returns an array of all the document’s current object style group names. Is that what you are looking for?

     

    //an array of all groups
    var os = GetOSGroups(app.activeDocument)
    alert(os)

    /**
    * Gets all object style groups inside of a group
    * @ param f the group to check, use app.activeDocument for all groups
    * @ return an array of group names
    */
    function GetOSGroups(f) {
    var a = []
    var osg = f.objectStyleGroups.everyItem().getElements()
    var gr
    for (var j = 0; j < osg.length; j++) {
    gr = osg[j];
    if (gr.objectStyleGroups.everyItem().getElements().length > 0) {
    a.push(gr.name)
    a = a.concat(GetOSGroups(gr))
    } else {
    a.push(gr.name)
    }
    }
    return a;
    }

     

    A list of all object style group names

     

    3 replies

    dublove
    dubloveAuthor
    Legend
    June 19, 2026

    Hi Manan Joshi

    Thank you very much.

    Easy to use, but nested feels a bit complicated.
    I'm a bit confused.
    @rob day Can it be simpler?

    rob day
    Community Expert
    rob dayCommunity ExpertCorrect answer
    Community Expert
    June 19, 2026

    Recursive loops are challenging to code. This returns an array of all the document’s current object style group names. Is that what you are looking for?

     

    //an array of all groups
    var os = GetOSGroups(app.activeDocument)
    alert(os)

    /**
    * Gets all object style groups inside of a group
    * @ param f the group to check, use app.activeDocument for all groups
    * @ return an array of group names
    */
    function GetOSGroups(f) {
    var a = []
    var osg = f.objectStyleGroups.everyItem().getElements()
    var gr
    for (var j = 0; j < osg.length; j++) {
    gr = osg[j];
    if (gr.objectStyleGroups.everyItem().getElements().length > 0) {
    a.push(gr.name)
    a = a.concat(GetOSGroups(gr))
    } else {
    a.push(gr.name)
    }
    }
    return a;
    }

     

    A list of all object style group names

     

    dublove
    dubloveAuthor
    Legend
    June 20, 2026

    Hi rob day.

    Thank you.
    A brand-new approach.
    deeply inspired.

    Community Expert
    June 19, 2026

    Try the following

    var creGroup = newGroup("myGroup", "objectStyleGroups");
    function newGroup(grn, sgc) {
    var d = app.activeDocument;

    function findGroupRecursively(currentLocation) {
    var groups = currentLocation[sgc];

    for (var i = 0; i < groups.length; i++) {
    if (groups[i].name === grn) {
    return groups[i];
    }
    var found = findGroupRecursively(groups[i]);
    if (found) {
    return found;
    }
    }
    return null;
    }
    var existingGroup = findGroupRecursively(d);
    if (existingGroup) {
    return true;
    }
    return d[sgc].add({ name: grn });
    }

     

    -Manan
    natasha052gandhi
    Participant
    June 19, 2026

    Hello, objectStyleGroups only returns top-level groups. Since InDesign has no allObjectStyleGroups, you'll need to recursively search through group.objectStyleGroups to find nested groups. Your current loop won't detect groups inside other groups.