1 # for slightly faster access
2 from bpy.__ops__ import add as op_add
3 from bpy.__ops__ import remove as op_remove
4 from bpy.__ops__ import dir as op_dir
5 from bpy.__ops__ import call as op_call
6 from bpy.__ops__ import as_string as op_as_string
7 from bpy.__ops__ import get_rna as op_get_rna
9 # Keep in sync with WM_types.h
12 'INVOKE_REGION_WIN':1,
21 class bpy_ops(object):
23 Fake module like class.
30 def remove(self, pyop):
33 def __getattr__(self, module):
35 gets a bpy.ops submodule
37 return bpy_ops_submodule(module)
43 # add this classes functions
44 for id_name in dir(self.__class__):
45 if not id_name.startswith('__'):
46 submodules.add(id_name)
48 for id_name in op_dir():
49 id_split = id_name.split('_OT_', 1)
51 if len(id_split) == 2:
52 submodules.add(id_split[0].lower())
54 submodules.add(id_split[0])
56 return list(submodules)
59 return "<module like class 'bpy.ops'>"
62 class bpy_ops_submodule(object):
64 Utility class to fake submodules.
68 __keys__ = ('module',)
70 def __init__(self, module):
73 def __getattr__(self, func):
75 gets a bpy.ops.submodule function
77 return bpy_ops_submodule_op(self.module, func)
83 module_upper = self.module.upper()
85 for id_name in op_dir():
86 id_split = id_name.split('_OT_', 1)
87 if len(id_split) == 2 and module_upper == id_split[0]:
88 functions.add(id_split[1])
90 return list(functions)
93 return "<module like class 'bpy.ops.%s'>" % self.module
95 class bpy_ops_submodule_op(object):
97 Utility class to fake submodule operators.
99 eg. bpy.ops.object.somefunc
101 __keys__ = ('module', 'func')
102 def __init__(self, module, func):
107 # submod.foo -> SUBMOD_OT_foo
108 return self.module.upper() + '_OT_' + self.func
110 def __call__(self, *args, **kw):
112 # Get the operator from blender
114 raise ValueError("only one argument for the execution context is supported ")
118 context = context_dict[args[0]]
120 raise ValueError("Expected a single context argument in: " + str(list(context_dict.keys())))
122 return op_call(self.idname(), kw, context)
125 return op_call(self.idname(), kw)
129 currently only used for '__rna__'
131 return op_get_rna(self.idname())
134 def __repr__(self): # useful display, repr(op)
135 return op_as_string(self.idname())
137 def __str__(self): # used for print(...)
138 return "<function bpy.ops.%s.%s at 0x%x'>" % (self.module, self.func, id(self))
143 # TODO, C macro's cant define settings :|
145 class MESH_OT_delete_edgeloop(bpy.types.Operator):
146 '''Export a single object as a stanford PLY with normals, colours and texture coordinates.'''
147 __idname__ = "mesh.delete_edgeloop"
148 __label__ = "Export PLY"
150 def execute(self, context):
151 bpy.ops.tfm.edge_slide(value=1.0)
152 bpy.ops.mesh.select_more()
153 bpy.ops.mesh.remove_doubles()
157 bpy.ops.add(MESH_OT_delete_edgeloop)