Skip to main content
dublove
Legend
Oct 2, 2025 10:56 AM UTC
Answered

How can I ensure newly created object styles are unique?

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?

rob day
rob dayCorrect answer
Community Expert
Oct 2, 2025 2:48 PM UTC

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
}

 

18 replies

Legend
Oct 2, 2025 11:46 AM UTC

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

 

P.

Translate
dublove
dubloveAuthor
Legend
Oct 2, 2025 12:03 PM UTC
Thank you very much. I remember there was an allparagraphs
alert(app.documents[0].allObjectStyles.itemByName(“a1”))
Still need to iterate?
 
Translate
rob day
Community Expert
Community Expert
Oct 2, 2025 1:00 PM UTC

Still need to iterate?

 

Yes, allObjectSyles is an Array not a Collection—an Array has no itemByName function.

 

Your alert(app.documents[0].allObjectStyles.itemByName(“a1”)) would throw an error:

 

Translate