Skip to main content
dublove
Legend
July 21, 2026
Answered

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

  • July 21, 2026
  • 1 reply
  • 28 views

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");

 

    Correct answer rob day

    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
    July 21, 2026

    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")
    }