Skip to main content
dublove
Legend
October 2, 2025
Answered

How can I ensure newly created object styles are unique?

  • October 2, 2025
  • 1 reply
  • 630 views

Object styles seem to allow duplicate names as long as they're in different groups.
The condition

"if(!d.objectStyles.itemByName(a1).isValid)" 

doesn't appear to check for "a1" within its own group.

Instead, it requires this approach:

if(!d.objectStyleGroups.itemByName(“AA”).objectStyles.itemByName(a1).isValid))

 

Since I don't know all group names, is there a way to check if the style `a1` exists in any group or outside all groups?

Correct answer rob day

How to efficiently determine if there is an a1?


With an Array you have to loop, something like this

 

alert(checForOS("a1"))
  
/**
* Check if an object style named n exists 
* @ param n 
* @ return true if object style named n exists * 
*/
function checForOS(n){
    var os = app.documents.item(0).allObjectStyles;
    var b = false
    for (var i = 0; i < os.length; i++){
        if (os[i].name == n) {
            b = true
        } 
    }; 
    return b
}

 

1 reply

Legend
October 2, 2025

You could use allObjectStyles to get an array, then check the array.

 

P.

dublove
dubloveAuthor
Legend
October 2, 2025

I feel the execution efficiency below is a bit low:

if(app.documents[0].objectStyleGroups.itemByName(“AA”).objectStyles.itemByName(“a1”).isValid)
rob day
Community Expert
Community Expert
October 2, 2025

That would also throw an error if the AA group does not exist.