I want to specify a component

I want to specify a component.
If ‘a’ is ‘0’,this can only choose the default first.
I didn’t find a solution.

layer = Glyphs.font.selectedLayers[0] # current layer
component = "g7694"
a = component
component = layer.components[a] # first component
layer.components[a].selected = True

You can have the same component twice. You can check for the componentName attribute though:

compname = "a"
print [c for c in Layer.components if c.componentName == compname]

… returns a list of all components that point to the glyph with the specified name.

The list comprehension in python is very difficult to understand. I can better understand the code like this:

compname = "a"
comp = None
for c in Layer.components:
	if c.componentName == compname:
		comp = c
print comp

Thank you very much.:grinning:

:star_struck:Perfect problem solving!:smiley:Thank you very very much.:grinning::star_struck:

This only gets the last matching component. To do the same as the list comprehension above:

compname = "a"
comps = [] # list of "a" components
for c in Layer.components:
	if c.componentName == compname:
print comps

Thank you very much.