# How can I find the selected metaball elements in Edit mode with Python?

If you have an active object you can find the currently selected sub elements; e. g. in an active mesh you can find the selected vertices while looping over them and check the property bpy.context.active_object.data.vertices[i].select.

In an active armature you can achieve the same with bpy.context.active_object.data.bones[i].select_head (or select_tail).

But for metaballs I cannot find a property bpy.context.active_object.data.elements[i].select or something like that. How can I retrieve the selected element(s) in a metaball object?

Background: In Edit mode you can add additional metaballs to a metaball object. I want to move the selected elements via Python.

• Well, beats me. Is it possible it isn't exposed in the python API? – kheetor Feb 20 '18 at 13:29

That one's not easy. I checked the Outliner to get the path to the elements:

I haven't been able to find the full selection yet, but the active ball can be found and moved:

import bpy
bpy.data.metaballs["Mball"].elements[2].co.x += 0.1
bpy.context.active_object.data.elements.active.co.x += 0.1
bpy.data.metaballs["Mball"].elements.active.co.x += 0.1


I hope somebody can prove me wrong but it might not be exposed to the API. Metaballs don't get a lot of limelight. In which case it would be worth to find the right dev to implement it.

Only workaround I can see is to keep the metaballs separated, select them in object mode, manipulate them there(they still merge anyway) and use that selection and join them afterwards. Depends on how many you need to move.

• The "active" command delivers only the first selected metaball in the list. Better than nothing, but the "grab" command is able to move all selected ones, even in edit mode. I hoped to have the same functionality in the Python API; seems I have to do without it ... – frisee Feb 20 '18 at 15:26
• @frisee I fully agree it's not remotely ideal. But I see only two other choices: bribe a dev or learn to change the code and commit it. – Haunt_House Feb 20 '18 at 15:59