Scripting problem with smartComponentPoleMapping

When I copy a smart component glyph to a new one.

For example, the source glyph is “_part.A”, with 3 smart axes Width, Height and Uroko.
And the copied one named “_part.B”, where I removed the Uroko axe.

I wrote a python script to set layer.smartComponentPoleMapping automatically.
However, an error occurred here:

   File "GlyphsApp/GlyphsApp/__init__.py", line 2037, in __setitem__
   File "_convenience.py", line 226, in __setitem__setObject_forKey_
     self.setObject_forKey_(container_wrap(value), container_wrap(key))
 objc.error: NSInternalInconsistencyException - -[__NSCFDictionary setObject:forKey:]: 
 mutating method sent to immutable object

I tried to print out layer.smartComponentPoleMapping values, they still be shown as old values (with no id).

image

although there’re only 2 axes in this glyph.

If I edit any component pole value in GUI, the problem will be fixed (in edited layer). Error still occurred in other layers.

image

p.s. Indeed, I removed Height axe and created a new one. And it’s name cannot be shown here. It look like that the ID/name dictionary is still the old one here.

Can I reload the layer.smartComponentPoleMapping axes data via scripting?


Glyphs Version 1286

I fixed the copying. For now, use this:

from GlyphsApp import objcObject
parts = dict(Layer.partSelection())
parts["new Property"] = 2
Layer.setPartSelection_(objcObject(parts))

Thank you Georg, it works now.

I used try/except to replace a new dict when problem occurred.

	try:
		box = layer.bounds.size
		if box.width == w_min: layer.smartComponentPoleMapping[wAxes.id] = 1
		if box.width == w_max: layer.smartComponentPoleMapping[wAxes.id] = 2
		if box.height == h_min: layer.smartComponentPoleMapping[hAxes.id] = 1
		if box.height == h_max: layer.smartComponentPoleMapping[hAxes.id] = 2
	except:
		parts = {}
		if box.width == w_min: parts['Width'] = 1
		if box.width == w_max: parts['Width'] = 2
		if box.height == h_min: parts['Height'] = 1
		if box.height == h_max: parts['Height'] = 2
		layer.setPartSelection_(objcObject(parts))

Now I stuck in a new problem.

I create component and set the smartComponentValues automatically by scripting, it works well.

	obj = GSComponent(partname)
	glyph.components.append(comp)

	if len(obj.component.smartComponentAxes) > 0:
		obj.smartComponentValues['Width'] = wVal
		obj.smartComponentValues['Height'] = hVal

However, if I try to adjust smart component values via dialog after scripting, Glyphs will crash everytime.


(Click OK and get crashed.)

If I resize each smart component by mouse before adjusting value via dialog, Glyphs will not crash.

Can you reproduce the issue?