Adding Axis Mappings custom parameter with script

Hello, I am trying to write a script that adds the Axis Mappings custom Parameter to my font with a specified set of values. I have tried everything under the sun, but when I run the script, the Axis Mappings parameter that is added is empty. When I run print(parameter) to list all parameters, it gives me <GSCustomParameter Axis Mappings: None>. My script is as follows:

for font in Glyphs.fonts:
	font.customParameters["Axis Mappings"] = "{\
    wght =     {\
        700 = 700;\
        300 = 307;\
        400 = 485;\
        200 = 200;\

What in the world am I doing wrong? I have tried numerous ways of leaving out the outermost brackets, shifting the indents around, lalala. Help. Please! Thank you :grin:

One way to find out is to create a custom parameter manually and then, in a quick script, ask for its value and for the type of the value with type(value).

Brilliant, thanks, I will try that.

So, in case I understood you correctly, I get the following for value and and type(value):

    wght =     {
        700 = 700;
        300 = 307;
        400 = 485;
        200 = 200;
<objective-c class __NSDictionaryM at 0x7fff88eb9028>

When I paste the value content into my code, it doesn’t work. The syntax is quite different from the other custom parameters. Any clue as to how to write it correctly?

You might need to put in a NSDictionary instead of a python dict.
There is a helper method in the wrapper:

from GlyphsApp import objcObject
print objcObject({"S":1})

I’m afraid I don’t follow. I’m quite the layman when it comes to this. What do I need to do with this in order to write an Axis Mappings custom parameter?

I should have looked at you code properly.

You are setting a string where you need to set a dict.

font.customParameters["Axis Mappings"] = {
	"wght": {
		700: 700,
		300: 307,
		400: 485,
		200: 200,
1 Like

You’re an absolute treasure. Thank you so much. That works perfectly! Have a fantastic day.