Skip to main content
Known Participant
May 2, 2008
Question

[JS] User Interface to Choose Layer Color (Get List of UIColors)

  • May 2, 2008
  • 14 replies
  • 1642 views
I know how to set layer color with UIColors so I am not somewhat familiar with how it works. I want to create a dialog (which I know how to do) that has a menu that lets a user choose their layer color. So I want to get a list of all the UIColors and present that as a menu to the user. I cannot figure out how to get this list of colors. I know how to access them individually, but I'd think it would act similar to an array. I can't figure out the code to access the list to use it in a menu. Is this possible and if so how?

P.S. I am supporting InDesign CS2 and CS3.

Thanks in advance.
Dan
This topic has been closed for replies.

14 replies

Inspiring
May 2, 2008
The $.writeln was for illustrative purposes only. You don't need it for building your list -- neither do you seem to need the counter variable.

The for ... in construction is JavaScript and has worked since CS, so what you have should work.

Dave
Known Participant
May 2, 2008
I did not know about that "in" construction, very interesting. But the writeIn seems to only work in CS3. Below is my code that works in CS3. Keep in mind that I can't use ScriptUI because I am supporting CS2. Is there anyway to make this work in both CS2 and CS3?

myInDesignListOfLayerColors = new Array()
counter = 0
for (j in UIColors) {
$.writeln( j )
myInDesignListOfLayerColors.push( j )
counter ++
}
myLayerColorMenu = dropdowns.add( {stringList:myInDesignListOfLayerColors, selectedIndex:0} )

Thanks again for your quick replies! This is getting close.
Dan
Inspiring
May 2, 2008
Dave is right. I used this with a ScriptUI dialog:

for( n in UIColors ) {
s = n.split("_");
for( i in s )
s = s.substr(0,1) + s.substr(1).toLowerCase();
win.colorDDn.add("item",s.join(" ")).value = UIColors;
}

Recently I've submitted a feature request to add draw event handling to dropdown items ...

Dirk
Inspiring
May 2, 2008
Does this help? Run this in ESTK and look at the result in the Console:

for (j in UIColors) {
$.writeln(j);
}

Because UIColors is an object, you can get the names of each of its properties using the for ... in construction.

Dave