Python bpy.ops() Examples
The following are 30
code examples of bpy.ops().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
bpy
, or try the search function
.
Example #1
Source File: archipack_manipulator.py From archipack with GNU General Public License v3.0 | 6 votes |
def move_linked(self, context, axis, value): """ Move an object along local axis takes care of linked too, fix issue #8 """ old = context.active_object bpy.ops.object.select_all(action='DESELECT') self.o.select = True context.scene.objects.active = self.o bpy.ops.object.select_linked(type='OBDATA') for o in context.selected_objects: if o != self.o: self._move(o, axis, value) bpy.ops.object.select_all(action='DESELECT') old.select = True context.scene.objects.active = old
Example #2
Source File: ops.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def __repr__(self): # useful display, repr(op) # import bpy idname = self.idname() as_string = op_as_string(idname) # XXX You never quite know what you get from bpy.types, # with operators... Operator and OperatorProperties # are shadowing each other, and not in the same way for # native ops and py ones! See T39158. # op_class = getattr(bpy.types, idname) op_class = op_get_rna(idname) descr = op_class.bl_rna.description # XXX, workaround for not registering # every __doc__ to save time on load. if not descr: descr = op_class.__doc__ if not descr: descr = "" return "# %s\n%s" % (descr, as_string)
Example #3
Source File: addon_updater_ops.py From coa_tools with GNU General Public License v3.0 | 6 votes |
def post_update_callback(res=None): # in case of error importing updater if updater.invalidupdater == True: return if res==None: # this is the same code as in conditional at the end of the register function # ie if "auto_reload_post_update" == True, comment out this code if updater.verbose: print("{} updater: Running post update callback".format(updater.addon)) #bpy.app.handlers.scene_update_post.append(updater_run_success_popup_handler) atr = addon_updater_updated_successful.bl_idname.split(".") getattr(getattr(bpy.ops, atr[0]),atr[1])('INVOKE_DEFAULT') global ran_update_sucess_popup ran_update_sucess_popup = True else: # some kind of error occured and it was unable to install, # offer manual download instead atr = addon_updater_updated_successful.bl_idname.split(".") getattr(getattr(bpy.ops, atr[0]),atr[1])('INVOKE_DEFAULT',error=res) return # function for asynchronous background check, which *could* be called on register
Example #4
Source File: addon_updater_ops.py From coa_tools with GNU General Public License v3.0 | 6 votes |
def updater_run_success_popup_handler(scene): global ran_update_sucess_popup ran_update_sucess_popup = True # in case of error importing updater if updater.invalidupdater == True: return try: bpy.app.handlers.scene_update_post.remove( updater_run_success_popup_handler) except: pass atr = addon_updater_updated_successful.bl_idname.split(".") getattr(getattr(bpy.ops, atr[0]),atr[1])('INVOKE_DEFAULT')
Example #5
Source File: fd_scene.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def set_cameras(self, current_scene, new_scene, wall): camera_data = bpy.data.cameras.new(new_scene.name) camera_obj = bpy.data.objects.new(name=camera_data.name + " Camera", object_data=camera_data) current_scene.objects.link(camera_obj) current_scene.camera = camera_obj camera_obj.data.type = 'ORTHO' camera_obj.rotation_euler.x = math.radians(90.0) camera_obj.rotation_euler.z = wall.obj_bp.rotation_euler.z camera_obj.location = wall.obj_bp.location bpy.ops.object.select_all(action='DESELECT') wall.get_wall_mesh().select = True bpy.ops.view3d.camera_to_view_selected() current_scene.camera = None current_scene.objects.unlink(camera_obj) new_scene.objects.link(camera_obj) new_scene.camera = camera_obj new_scene.render.resolution_y = 1280 bpy.data.cameras[new_scene.name].ortho_scale += self.padding
Example #6
Source File: fd_scene.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def clear_and_collect_data(self,context): for product in self.products: self.products.remove(product) for wall in self.walls: self.walls.remove(wall) bpy.ops.fd_material.get_materials() for scene in bpy.data.scenes: if not scene.mv.plan_view_scene and not scene.mv.elevation_scene: for obj in scene.objects: if not obj.mv.dont_export: if obj.mv.type == 'BPWALL': self.walls.append(obj) if obj.mv.type == 'BPASSEMBLY': if obj.mv.type_group == 'PRODUCT': self.products.append(obj) if obj.cabinetlib.type_mesh == 'BUYOUT' and obj.parent is None: self.buyout_products.append(obj)
Example #7
Source File: wm.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def invoke(self, context, event): wm = context.window_manager data_path = self.data_path prop_string = self.prop_string # same as eval("bpy.ops." + data_path) op_mod_str, ob_id_str = data_path.split(".", 1) op = getattr(getattr(bpy.ops, op_mod_str), ob_id_str) del op_mod_str, ob_id_str try: op_rna = op.get_rna() except KeyError: self.report({'ERROR'}, "Operator not found: bpy.ops.%s" % data_path) return {'CANCELLED'} def draw_cb(self, context): layout = self.layout pie = layout.menu_pie() pie.operator_enum(data_path, prop_string) wm.popup_menu_pie(draw_func=draw_cb, title=op_rna.bl_rna.name, event=event) return {'FINISHED'}
Example #8
Source File: wm.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def execute(self, context): op_strings = [] tot = 0 for op_module_name in dir(bpy.ops): op_module = getattr(bpy.ops, op_module_name) for op_submodule_name in dir(op_module): op = getattr(op_module, op_submodule_name) text = repr(op) if text.split("\n")[-1].startswith("bpy.ops."): op_strings.append(text) tot += 1 op_strings.append('') textblock = bpy.data.texts.new("OperatorList.txt") textblock.write('# %d Operators\n\n' % tot) textblock.write('\n'.join(op_strings)) self.report({'INFO'}, "See OperatorList.txt textblock") return {'FINISHED'} # ----------------------------------------------------------------------------- # Add-on Operators
Example #9
Source File: presets.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def execute(self, context): from os.path import basename, splitext filepath = self.filepath # change the menu title to the most recently chosen option preset_class = getattr(bpy.types, self.menu_idname) preset_class.bl_label = bpy.path.display_name(basename(filepath)) ext = splitext(filepath)[1].lower() # execute the preset using script.python_file_run if ext == ".py": bpy.ops.script.python_file_run(filepath=filepath) elif ext == ".xml": import rna_xml rna_xml.xml_file_run(context, filepath, preset_class.preset_xml_map) else: self.report({'ERROR'}, "unknown filetype: %r" % ext) return {'CANCELLED'} return {'FINISHED'}
Example #10
Source File: import_x3d.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def importMesh_PointSet(geom, ancestry, _): # VRML not x3d coord = geom.getChildBySpec('Coordinate') # works for x3d and vrml if coord: points = coord.getFieldAsArray('point', 3, ancestry) else: points = [] # vcolor = geom.getChildByName('color') # blender dosnt have per vertex color bpymesh = bpy.data.meshes.new("PointSet") bpymesh.vertices.add(len(points)) bpymesh.vertices.foreach_set("co", [a for v in points for a in v]) # No need to validate bpymesh.update() return bpymesh # ----------------------------------------------------------------------------------- # Primitives # SA: they used to use bpy.ops for primitive creation. That was # unbelievably slow on complex scenes. I rewrote to generate meshes # by hand.
Example #11
Source File: wm.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def invoke(self, context, event): wm = context.window_manager data_path = self.data_path prop_string = self.prop_string # same as eval("bpy.ops." + data_path) op_mod_str, ob_id_str = data_path.split(".", 1) op = getattr(getattr(bpy.ops, op_mod_str), ob_id_str) del op_mod_str, ob_id_str try: op_rna = op.get_rna() except KeyError: self.report({'ERROR'}, "Operator not found: bpy.ops.%s" % data_path) return {'CANCELLED'} def draw_cb(self, context): layout = self.layout pie = layout.menu_pie() pie.operator_enum(data_path, prop_string) wm.popup_menu_pie(draw_func=draw_cb, title=op_rna.bl_rna.name, event=event) return {'FINISHED'}
Example #12
Source File: presets.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def execute(self, context): from os.path import basename, splitext filepath = self.filepath # change the menu title to the most recently chosen option preset_class = getattr(bpy.types, self.menu_idname) preset_class.bl_label = bpy.path.display_name(basename(filepath)) ext = splitext(filepath)[1].lower() # execute the preset using script.python_file_run if ext == ".py": bpy.ops.script.python_file_run(filepath=filepath) elif ext == ".xml": import rna_xml rna_xml.xml_file_run(context, filepath, preset_class.preset_xml_map) else: self.report({'ERROR'}, "unknown filetype: %r" % ext) return {'CANCELLED'} return {'FINISHED'}
Example #13
Source File: addon_updater_ops.py From kaleidoscope with GNU General Public License v3.0 | 6 votes |
def updater_run_success_popup_handler(scene): global ran_update_sucess_popup ran_update_sucess_popup = True # in case of error importing updater if updater.invalidupdater == True: return try: bpy.app.handlers.scene_update_post.remove( updater_run_success_popup_handler) except: pass atr = addon_updater_updated_successful.bl_idname.split(".") getattr(getattr(bpy.ops, atr[0]),atr[1])('INVOKE_DEFAULT')
Example #14
Source File: utils.py From addon_common with GNU General Public License v3.0 | 6 votes |
def still_registered(self, oplist): if getattr(still_registered, 'is_broken', False): return False def is_registered(): cur = bpy.ops for n in oplist: if not hasattr(cur, n): return False cur = getattr(cur, n) try: StructRNA.path_resolve(self, "properties") except: print('no properties!') return False return True if is_registered(): return True still_registered.is_broken = True print('bpy.ops.%s is no longer registered!' % '.'.join(oplist)) return False
Example #15
Source File: io_export_selected.py From naoqi_bridge with BSD 3-Clause "New" or "Revised" License | 6 votes |
def iter_exporters(): #categories = dir(bpy.ops) categories = ["export_anim", "export_mesh", "export_scene"] for category_name in categories: op_category = getattr(bpy.ops, category_name) for name in dir(op_category): total_name = category_name + "." + name if total_name == ExportSelected.bl_idname: continue if "export" in total_name: op = getattr(op_category, name) yield total_name, op
Example #16
Source File: io_export_selected.py From naoqi_bridge with BSD 3-Clause "New" or "Revised" License | 6 votes |
def execute(self, context): with ToggleObjectMode(undo=None): self.clear_world(context) if self.format: props = {} for key in CurrentFormatProperties._keys(): props[key] = getattr(self.format_props, key) props["filepath"] = self.filepath op = get_op(self.format) op(**props) else: bpy.ops.wm.save_as_mainfile( filepath=self.filepath, copy=True, ) bpy.ops.ed.undo() bpy.ops.ed.undo_push(message="Export Selected") return {'FINISHED'}
Example #17
Source File: addon_updater_ops.py From CrowdMaster with GNU General Public License v3.0 | 6 votes |
def updater_run_success_popup_handler(scene): global ran_update_sucess_popup ran_update_sucess_popup = True # in case of error importing updater if updater.invalidupdater == True: return try: bpy.app.handlers.scene_update_post.remove( updater_run_success_popup_handler) except: pass atr = addon_updater_updated_successful.bl_idname.split(".") getattr(getattr(bpy.ops, atr[0]),atr[1])('INVOKE_DEFAULT')
Example #18
Source File: addon_updater_ops.py From CrowdMaster with GNU General Public License v3.0 | 6 votes |
def post_update_callback(): # in case of error importing updater if updater.invalidupdater == True: return # this is the same code as in conditional at the end of the register function # ie if "auto_reload_post_update" == True, comment out this code if updater.verbose: print("{} updater: Running post update callback".format(updater.addon)) #bpy.app.handlers.scene_update_post.append(updater_run_success_popup_handler) atr = addon_updater_updated_successful.bl_idname.split(".") getattr(getattr(bpy.ops, atr[0]),atr[1])('INVOKE_DEFAULT') global ran_update_sucess_popup ran_update_sucess_popup = True return # function for asynchronous background check, which *could* be called on register
Example #19
Source File: wm.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def execute(self, context): import addon_utils module_name = self.module modules = addon_utils.modules(refresh=False) mod = addon_utils.addons_fake_modules.get(module_name) if mod is not None: info = addon_utils.module_bl_info(mod) info["show_expanded"] = True bpy.context.user_preferences.active_section = 'ADDONS' context.window_manager.addon_filter = 'All' context.window_manager.addon_search = info["name"] bpy.ops.screen.userpref_show('INVOKE_DEFAULT') return {'FINISHED'} # Note: shares some logic with WM_OT_addon_install # but not enough to de-duplicate. Fixes here may apply to both.
Example #20
Source File: ops.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def __repr__(self): # useful display, repr(op) # import bpy idname = self.idname() as_string = op_as_string(idname) # XXX You never quite know what you get from bpy.types, # with operators... Operator and OperatorProperties # are shadowing each other, and not in the same way for # native ops and py ones! See T39158. # op_class = getattr(bpy.types, idname) op_class = op_get_rna(idname) descr = op_class.bl_rna.description # XXX, workaround for not registering # every __doc__ to save time on load. if not descr: descr = op_class.__doc__ if not descr: descr = "" return "# %s\n%s" % (descr, as_string)
Example #21
Source File: addon_updater_ops.py From archipack with GNU General Public License v3.0 | 6 votes |
def post_update_callback(): # in case of error importing updater if updater.invalidupdater == True: return # this is the same code as in conditional at the end of the register function # ie if "auto_reload_post_update" == True, comment out this code if updater.verbose: print("{} updater: Running post update callback".format(updater.addon)) #bpy.app.handlers.scene_update_post.append(updater_run_success_popup_handler) atr = ARCHIPACK_OT_updater_updated_successful.bl_idname.split(".") getattr(getattr(bpy.ops, atr[0]),atr[1])('INVOKE_DEFAULT') global ran_update_sucess_popup ran_update_sucess_popup = True return # function for asynchronous background check, which *could* be called on register
Example #22
Source File: addon_updater_ops.py From archipack with GNU General Public License v3.0 | 6 votes |
def updater_run_success_popup_handler(scene): global ran_update_sucess_popup ran_update_sucess_popup = True # in case of error importing updater if updater.invalidupdater == True: return try: bpy.app.handlers.scene_update_post.remove( updater_run_success_popup_handler) except: pass atr = ARCHIPACK_OT_updater_updated_successful.bl_idname.split(".") getattr(getattr(bpy.ops, atr[0]),atr[1])('INVOKE_DEFAULT')
Example #23
Source File: addon_updater_ops.py From kaleidoscope with GNU General Public License v3.0 | 5 votes |
def execute(self,context): # in case of error importing updater if updater.invalidupdater == True: return {'CANCELLED'} if updater.manual_only == True: bpy.ops.wm.url_open(url=updater.website) if updater.update_ready == True: # if it fails, offer to open the website instead try: res = updater.run_update( force=False, callback=post_update_callback, clean=self.clean_install) # should return 0, if not something happened if updater.verbose: if res==0: print("Updater returned successful") else: print("Updater returned "+str(res)+", error occurred") except Exception as e: updater._error = "Error trying to run update" updater._error_msg = str(e) atr = addon_updater_install_manually.bl_idname.split(".") getattr(getattr(bpy.ops, atr[0]),atr[1])('INVOKE_DEFAULT') elif updater.update_ready == None: (update_ready, version, link) = updater.check_for_update(now=True) # re-launch this dialog atr = addon_updater_install_popup.bl_idname.split(".") getattr(getattr(bpy.ops, atr[0]),atr[1])('INVOKE_DEFAULT') elif updater.update_ready == False: self.report({'INFO'}, "Nothing to update") else: self.report({'ERROR'}, "Encountered problem while trying to update") return {'FINISHED'}
Example #24
Source File: utils.py From addon_common with GNU General Public License v3.0 | 5 votes |
def registered_object_add(self): global registered_objects opid = self.operator_id print('Registering bpy.ops.%s' % opid) registered_objects[opid] = (self, opid.split('.'))
Example #25
Source File: operators.py From BlenderRobotDesigner with GNU General Public License v2.0 | 5 votes |
def get_registered_operator(operator): """ Helper function that gets the registered Blender :term:`operator` based on its ``bl_idname`` tag. :param operator: A subclass of :class:`RDOperator` class. :return: The actually callable operator function. One has to pass :term:`keyword arguments` that match the name of the classes attributes. """ #logger.debug('For debug only') return getattr(getattr(bpy.ops, PLUGIN_PREFIX), operator.bl_idname.replace(PLUGIN_PREFIX + '.', ''))
Example #26
Source File: sdf_import.py From BlenderRobotDesigner with GNU General Public License v2.0 | 5 votes |
def import_sphere(self, model): """ Adds a geometry to the blender scene. Uses the self.file_name variable of the parenting context :param model: A sdf_dom.visual object. :return: Returns the transformation in the origin element (a 4x4 blender matrix). """ # determine prefix path for loading meshes in case of paths relative to ROS_PACKAGE_PATH prefix_folder = "" c_radius = model.geometry[0].sphere[0].radius[0] bpy.ops.mesh.primitive_uv_sphere_add(segments=8, ring_count=4, size=c_radius, location=(0, 0, 0)) # bpy.ops.mesh.primitive_cylinder_add(depth=c_depth,radius=c_radius, location=(0, 0, 0)) bpy.context.active_object.RobotEditor.fileName = os.path.basename(model.name) self.logger.debug('Active robot name: %s', bpy.context.active_object.RobotEditor.fileName) model_name = bpy.context.active_object.name #bpy.context.active_object.type = 'ARMATURE' model_type = bpy.context.active_object.type self.logger.debug('model_name (geometry): %s', model_name) self.logger.debug('model_type (geometry): %s', model_type) self.logger.debug('model_geometry_sphere: radius %s, depth ', c_radius) # todo: if geometry pose is missing if not model.pose: model_posexyz = [0, 0, 0] model_poserpy = [0, 0, 0] else: self.logger.debug('model_pose (geometry): %s', model.pose[0]) model_posexyz = string_to_list(model.pose[0])[0:3] model_poserpy = string_to_list(model.pose[0])[3:] return Matrix.Translation(Vector(model_posexyz)) * \ Euler(model_poserpy, 'XYZ').to_matrix().to_4x4()
Example #27
Source File: sdf_import.py From BlenderRobotDesigner with GNU General Public License v2.0 | 5 votes |
def import_cylinder(self, model): """ Adds a geometry to the blender scene. Uses the self.file_name variable of the parenting context :param model: A sdf_dom.visual object. :return: Returns the transformation in the origin element (a 4x4 blender matrix). """ # determine prefix path for loading meshes in case of paths relative to ROS_PACKAGE_PATH prefix_folder = "" c_radius = model.geometry[0].cylinder[0].radius[0] c_depth = model.geometry[0].cylinder[0].length[0] bpy.ops.mesh.primitive_cylinder_add(depth=c_depth,radius=c_radius, location=(0, 0, 0)) bpy.context.active_object.RobotEditor.fileName = os.path.basename(model.name) self.logger.debug('Active robot name: %s', bpy.context.active_object.RobotEditor.fileName) model_name = bpy.context.active_object.name #bpy.context.active_object.type = 'ARMATURE' model_type = bpy.context.active_object.type self.logger.debug('model_name (geometry): %s', model_name) self.logger.debug('model_type (geometry): %s', model_type) self.logger.debug('model_geometry_cylinder: radius %s, depth %s', c_radius, c_depth) # todo: if geometry pose is missing if not model.pose: model_posexyz = [0, 0, 0] model_poserpy = [0, 0, 0] else: self.logger.debug('model_pose (geometry): %s', model.pose[0]) model_posexyz = string_to_list(model.pose[0])[0:3] model_poserpy = string_to_list(model.pose[0])[3:] return Matrix.Translation(Vector(model_posexyz)) * \ Euler(model_poserpy, 'XYZ').to_matrix().to_4x4()
Example #28
Source File: io_export_selected.py From naoqi_bridge with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_op(idname): category_name, op_name = idname.split(".") category = getattr(bpy.ops, category_name) return getattr(category, op_name)
Example #29
Source File: console_python.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def banner(context): sc = context.space_data version_string = sys.version.strip().replace('\n', ' ') add_scrollback("PYTHON INTERACTIVE CONSOLE %s" % version_string, 'OUTPUT') add_scrollback("", 'OUTPUT') add_scrollback("Command History: Up/Down Arrow", 'OUTPUT') add_scrollback("Cursor: Left/Right Home/End", 'OUTPUT') add_scrollback("Remove: Backspace/Delete", 'OUTPUT') add_scrollback("Execute: Enter", 'OUTPUT') add_scrollback("Autocomplete: Ctrl-Space", 'OUTPUT') add_scrollback("Zoom: Ctrl +/-, Ctrl-Wheel", 'OUTPUT') add_scrollback("Builtin Modules: bpy, bpy.data, bpy.ops, " "bpy.props, bpy.types, bpy.context, bpy.utils, " "bgl, blf, mathutils", 'OUTPUT') add_scrollback("Convenience Imports: from mathutils import *; " "from math import *", 'OUTPUT') add_scrollback("Convenience Variables: C = bpy.context, D = bpy.data", 'OUTPUT') add_scrollback("", 'OUTPUT') sc.prompt = PROMPT return {'FINISHED'} # workaround for readline crashing, see: T43491
Example #30
Source File: io_export_selected.py From naoqi_bridge with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __enter__(self): if self.mode: edit_preferences = bpy.context.user_preferences.edit self.global_undo = edit_preferences.use_global_undo self.prev_mode = bpy.context.object.mode if self.prev_mode != self.mode: if self.undo is not None: edit_preferences.use_global_undo = self.undo bpy.ops.object.mode_set(mode=self.mode) return self