Skip to main content
dublove
Legend
Jul 21, 2026 4:15 PM UTC
Answered

How to obtain its upper level from "A style"?

If I only knew:

myStyleA=  app.documents[0].objectStyleGroups.itemByName(groupName).objectStyles.itemByName("A");
Is it possible to directly obtain the same level 'B' path from myStyleA


Like this:

myStyleB=myStyleA.parent.itemByname("B");


Instead of rewriting it completely:
 

myStyleB=app.documents[0].objectStyleGroups.itemByName(groupName).objectStyles.itemByName("B");

 

    rob day
    rob dayCorrect answer
    Community Expert
    Jul 21, 2026 7:43 PM UTC

    Is it possible to directly obtain the same level 'B' path from myStyleA

     

    Needs to be .parent.objectStyles.itemByName(“B”)—not .parent.itemByName(“B”). You are trying to get a object style not an object style group (which is what parent is returning in this case). 

     

    Also you probably should make sure “B” is valid:

     

    var g = app.documents[0].objectStyleGroups.itemByName("MyGroup").objectStyles.itemByName("A")
    var i = g.parent.objectStyles.itemByName("B");

    //check if the targeted object style is valid
    if (i.isValid) {
    alert("An Object Style Named " + i.name + " is valid")
    } else {
    alert("Style B is not valid")
    }

     

    1 reply

    rob day
    Community Expert
    rob dayCommunity ExpertCorrect answer
    Community Expert
    Jul 21, 2026 7:43 PM UTC

    Is it possible to directly obtain the same level 'B' path from myStyleA

     

    Needs to be .parent.objectStyles.itemByName(“B”)—not .parent.itemByName(“B”). You are trying to get a object style not an object style group (which is what parent is returning in this case). 

     

    Also you probably should make sure “B” is valid:

     

    var g = app.documents[0].objectStyleGroups.itemByName("MyGroup").objectStyles.itemByName("A")
    var i = g.parent.objectStyles.itemByName("B");

    //check if the targeted object style is valid
    if (i.isValid) {
    alert("An Object Style Named " + i.name + " is valid")
    } else {
    alert("Style B is not valid")
    }

     

    Translate