Composite Recipes with Smart Components

Is it possible to write a composite recipe that combines smart components, but the recipe calls for specific Smart Component parameters?
thanks!

Here is a macro that you can run in WindowMacro Panel:

recipes = """
comp1[param1=0,param2=100]+comp2+comp3[param0=50]=glyph1
comp4[param1=75,param2=0]=glyph2
comp5[param1=25]+comp6=glyph3
"""

for recipe in recipes.strip().split("\n"):
	sides = recipe.rsplit("=", 1)
	glyph_name = sides[1].strip()
	glyph = GSGlyph(glyph_name)

	component_codes = [x.strip() for x in sides[0].split("+")]
	component_specs = []

	for component_code in component_codes:
		code_split = component_code.split("[")
		component_name = code_split[0]
		parameter_specs = []

		if len(code_split) > 1:
			parameter_codes = code_split[1].strip("]").split(",")

			def parse_parameter_code(parameter_code):
				spec = parameter_code.split("=")
				name = spec[0].strip()
				value = float(sides[1].strip())
				return name, value

			parameter_specs = [parse_parameter_code(x) for x in parameter_codes]

		component_specs.append((component_name, parameter_specs))

	Font.glyphs.append(glyph)
	
	for layer in glyph.layers:
		for component_name, parameter_specs in component_specs:
			component = GSComponent(component_name)
			for name, value in parameter_specs:
				component.smartComponentValues[name] = value
			layer.shapes.append(component)

You only need to change the code at the top between the """ and """. The recipes are written like so, one recipe per line:

comp1[param1=0,param2=100]+comp2+comp3[param0=50]=glyph1

where comp#, param#, and glyph# are placeholder for your component, parameter, and glyph names.

1 Like

thank you thank you Florian! I can’t to try this out!
-Jane