TypeError: 'GSComponent' object does not support indexing

Trying to add kerning to this script https://github.com/mekkablue/Glyphs-Scripts/blob/master/Components/Align%20All%20Components.py and I need to be able to enumerate and get the next component but I can’t do that? Any ideas?

def process( thisGlyph ):
	numberOfLayers = len( thisGlyph.layers )
	for i in range( numberOfLayers )[::-1]:
		thisLayer = thisGlyph.layers[i]
		thisFontMasterID = thisLayer.associatedFontMaster().id
		if thisLayer.layerId == thisFontMasterID:
			advance = 0.0
			allComponents = thisLayer.components
			for i, thisComponent in enumerate(allComponents):
				thisKerningPair = 0
				if i>0:
					previousComponent = thisLayer.components[i-1]
					thisKerningPair = Font.kerningForPair(thisFontMasterID, previousComponent, thisComponent)
				thisComponent.position = NSPoint( advance, 0.0 )
				advance += thisComponent.component.layers[thisFontMasterID].width + thisKerningPair
			thisLayer.width = advance

Which line gives you the error?

The error says that you tried to index a single component like myComponent[4], but this excerpt doesn’t show such a situation. Did you save the script before running it again?

OH i figured it out i had reference component.componentName! :slight_smile:

1 Like