Properly apply modifiers. Context must somehow be checked, probably when selection contains group instances, there pops up an error that has to be fixed.