Your code should work, but it would be very slow. You don’t need the “import robofab”
Try this (it is not pretty but should work)
font = Glyphs.font
ArrayController = font.parent.windowController().glyphsController()
SelectionIndexes = ArrayController.selectionIndexes()
NewSelectionIndexes = NSMutableIndexSet.indexSet()
for i in range(len(font.glyphs)):
(tav)if not SelectionIndexes.containsIndex_(i):
For RoboFab script, it is better to import the RoboFab wrapper from https://github.com/schriftgestalt/Glyphs-Scripts
Put the objectsGS.py in the root folder of your scripts and instead of robofab, import objectsGS at the beginning of your .py.
But, seriously, why RoboFab? It makes no sense if you try to call an app function of Glyphs. Actually, Glyphs has its own Python API: http://docu.glyphsapp.com
The script that Georg posted above also works without RoboFab. The code may look a little weird to a Python scripter, because it directly uses app functions through the Python ObjectiveC bridge. This makes the script very fast.
Why RoboFab? I just took a class in Python around Robofab/Robofont scripting with Joancarles Casasín and Gustavo Ferreira. They explained that if a font editor supports Robofab, then it is possible to run scripts written for Robofab (but I understand that scripts for Robofont can’t be simply copy-pasted into Glyphs and be expected to work!).
Most scripts written for roboFab still use some native API for things that are not covered by roboFab (like multiple master in Glyphs). So you usually need to adjust a few little things. And sometime you run into the situation where the app does not implement something properly.