I want to write a script in Python and add customparameters ["color palettes"] on the master. How should value be assigned?

I want to write a script ,add customparameters [“Color Palettes”] on the master. How should value be assigned?

To get started, add one manually and print it to the console. That should give you an idea how it works.

But I would recommend to put the palettes on the font. That is possible since a few versions.

Maybe what I described is not very correct. I mean, I want to know the python type of customParameters [“Color Palettes”]. What I print:

font =Glyphs.font
master = font.masters[0]
cp = master.customParameters['Color Palettes']
print type(cp)
print cp

it’s out:
<objective-c class __NSArrayM at 0x7ff85837c4d0>
(
(
“Display P3 colorspace 0.91747 0.419262 0.416446 0.44”,
“Display P3 colorspace 0.428862 0.91747 0.578691 0.584287”
)
)

I want to be able to add custom parameter ‘Color Palettes’ through script

What do you see in the output. If you look at each line, you should be able to figure it out.
Or is there something in particular that you don’t understand?

I want to assign a value to master.customParameters[‘Color Palettes’] through python script, but I can’t assign a value correctly. I want to know what type of master.customParameters[‘Color Palettes’] is in Python

I understand what you are asking. Im trying to teach you how to solve problems like this on your own.

Have you read the output of the script line by line?

<objective-c class __NSArrayM at 0x7ff85837c4d0>

A NSArray is the base list type in ObjectiveC.

(
(
“Display P3 colorspace 0.91747 0.419262 0.416446 0.44”,
“Display P3 colorspace 0.428862 0.91747 0.578691 0.584287”
)
)

The first and second line are opening parents that tell you that this are arrays/lists. So we have an array of array. The outer array is the list of “Palettes” and the inner list contains the colors. Those are NSColor (a ObjectiveC class representing colors) objects.

So to build that parameters you can do something like this:

palette1 = list(NSColor.greenColor(), NSColor.blueColor())
palette2 = list(NSColor.yellowColor(), NSColor.redColor())
parameter = list(palette1, palette2)
font.customParameters['Color Palettes'] = parameter

I’m really sorry. The automatic translation of my browser may not be very correct, so I misinterpret your meaning.

No problem. I suspected something like this. Do you understand me explanation now?

Yes,thanks very much!