Hi,
Could some one help me with a py question?
How can I know what enums an operator can take in an argument?
For example mode changing in 3D view is done by:
How do I find out what modes are available for this object type? For example only ‘OBJECT’ is available for lamps, but meshes also have ‘EDIT’ and so on.
Try the operator in the console and intentionally make an error in your keyword argument. eg
bpy.ops.object.mode-set(mode = 'What the heck goes here')
will give you back
Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
File "C:\Dev\Blender\blender-2.65-r53841-win64\2.65\scripts\modules\bpy\ops.py", line 188, in __call__
ret = op_call(self.idname_py(), None, kw)
TypeError: Converting py args to operator properties: enum "What the heck goes here" not found in ('OBJECT', 'EDIT', 'SCULPT', 'VERTEX_PAINT', 'WEIGHT_PAINT', 'TEXTURE_PAINT')
From the “Blender Experimental 2012” key-map I have found the following code that makes a menu with the available modes.
class ModeSwitchMenu(bpy.types.Menu):
""" A menu for switching between object modes.
"""
bl_idname = "OBJECT_MT_mode_switch_menu"
bl_label = "Switch Mode"
def draw(self, context):
layout = self.layout
layout.operator_enum("object.mode_set", "mode")
bpy.utils.register_class(ModeSwitchMenu)
# Temporary work around: Blender does not properly limit the mode switch menu
# items until the first mode switch (e.g. mesh objects will show pose mode as
# an option).
# TODO: file a bug report for this behavior.
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
So this is almost what I want, but I don´t want the menu.
the mode menu is generated by c-code, operator_enum calls a c-code function as well. I don’t see a chance with current API to retrieve the possible modes. You better test all object types and write the modes down.