Python bpy.types.Operator() Examples

The following are 11 code examples of bpy.types.Operator(). 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.types , or try the search function .
Example #1
Source File: wm.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
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 #2
Source File: wm.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
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 #3
Source File: archipack_fence.py    From archipack with GNU General Public License v3.0 6 votes vote down vote up
def execute(self, context):
        d = archipack_fence.datablock(context.active_object)

        if d is None:
            self.report({'WARNING'}, "Archipack: Operator only valid with fence")
            return {'CANCELLED'}

        if self.part == "SUB":
            part_obj = bpy.data.objects.get(d.user_defined_subs)
            if part_obj is None:
                self.report({'WARNING'}, "Archipack: User defined sub object not found")
                return {'CANCELLED'}
            d.subs_x, d.subs_y, d.subs_z = part_obj.dimensions.x, part_obj.dimensions.y, part_obj.dimensions.z
        else:
            part_obj = bpy.data.objects.get(d.user_defined_post)
            if part_obj is None:
                self.report({'WARNING'}, "Archipack: User defined post object not found")
                return {'CANCELLED'}
            d.post_x, d.post_y, d.post_z = part_obj.dimensions.x, part_obj.dimensions.y, part_obj.dimensions.z

        return {'FINISHED'} 
Example #4
Source File: operator_file_export.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def menu_func_export(self, context):
    self.layout.operator(ExportSomeData.bl_idname, text="Text Export Operator") 
Example #5
Source File: operator_file_import.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def menu_func_import(self, context):
    self.layout.operator(ImportSomeData.bl_idname, text="Text Import Operator") 
Example #6
Source File: presets.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def preset_values(self):
        properties_blacklist = Operator.bl_rna.properties.keys()

        prefix, suffix = self.operator.split("_OT_", 1)
        op = getattr(getattr(bpy.ops, prefix.lower()), suffix)
        operator_rna = op.get_rna().bl_rna
        del op

        ret = []
        for prop_id, prop in operator_rna.properties.items():
            if not (prop.is_hidden or prop.is_skip_save):
                if prop_id not in properties_blacklist:
                    ret.append("op.%s" % prop_id)

        return ret 
Example #7
Source File: operator_file_import.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def menu_func_import(self, context):
    self.layout.operator(ImportSomeData.bl_idname, text="Text Import Operator") 
Example #8
Source File: presets.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def preset_values(self):
        properties_blacklist = Operator.bl_rna.properties.keys()

        prefix, suffix = self.operator.split("_OT_", 1)
        op = getattr(getattr(bpy.ops, prefix.lower()), suffix)
        operator_rna = op.get_rna().bl_rna
        del op

        ret = []
        for prop_id, prop in operator_rna.properties.items():
            if not (prop.is_hidden or prop.is_skip_save):
                if prop_id not in properties_blacklist:
                    ret.append("op.%s" % prop_id)

        return ret 
Example #9
Source File: io.py    From phobos with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def invoke(self, context, event):
        """

        Args:
          context: 
          event: 

        Returns:

        """
        self.filepath = bUtils.getPhobosPreferences().modelsfolder
        context.window_manager.fileselect_add(self)
        return {'RUNNING_MODAL'}


# TODO use it or delete it... Own dev branch?
# class ViewExportOperator(Operator):
#     """Open a file explorer window in the export path"""
#     bl_idname = "phobos.view_export"
#     bl_label = "Export Scene"
#     bl_options = {'REGISTER', 'UNDO'}
#
#     def execute(self, context):
#        bpy.ops.wm.path_open(filepath=bpy.types.World.path)
#        return {'FINISHED'}


# FIXME: parameter? 
Example #10
Source File: wm.py    From Fluid-Designer with GNU General Public License v3.0 4 votes vote down vote up
def _wm_doc_get_id(doc_id, do_url=True, url_prefix=""):
    id_split = doc_id.split(".")
    url = rna = None

    if len(id_split) == 1:  # rna, class
        if do_url:
            url = "%s/bpy.types.%s.html" % (url_prefix, id_split[0])
        else:
            rna = "bpy.types.%s" % id_split[0]

    elif len(id_split) == 2:  # rna, class.prop
        class_name, class_prop = id_split

        # an operator (common case - just button referencing an op)
        if hasattr(bpy.types, class_name.upper() + "_OT_" + class_prop):
            if do_url:
                url = ("%s/bpy.ops.%s.html#bpy.ops.%s.%s" % (url_prefix, class_name, class_name, class_prop))
            else:
                rna = "bpy.ops.%s.%s" % (class_name, class_prop)
        else:
            rna_class = getattr(bpy.types, class_name)

            # an operator setting (selected from a running operator), rare case
            # note: Py defined operators are subclass of Operator,
            #       C defined operators are subclass of OperatorProperties.
            #       we may need to check on this at some point.
            if issubclass(rna_class, (bpy.types.Operator, bpy.types.OperatorProperties)):
                # note: ignore the prop name since we don't have a way to link into it
                class_name, class_prop = class_name.split("_OT_", 1)
                class_name = class_name.lower()
                if do_url:
                    url = ("%s/bpy.ops.%s.html#bpy.ops.%s.%s" % (url_prefix, class_name, class_name, class_prop))
                else:
                    rna = "bpy.ops.%s.%s" % (class_name, class_prop)
            else:
                # an RNA setting, common case

                # detect if this is a inherited member and use that name instead
                rna_parent = rna_class.bl_rna
                rna_prop = rna_parent.properties[class_prop]
                rna_parent = rna_parent.base
                while rna_parent and rna_prop == rna_parent.properties.get(class_prop):
                    class_name = rna_parent.identifier
                    rna_parent = rna_parent.base

                if do_url:
                    url = ("%s/bpy.types.%s.html#bpy.types.%s.%s" % (url_prefix, class_name, class_name, class_prop))
                else:
                    rna = ("bpy.types.%s.%s" % (class_name, class_prop))

    return url if do_url else rna 
Example #11
Source File: editing.py    From phobos with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def execute(self, context):
        """

        Args:
          context: 

        Returns:

        """
        newroot = context.active_object
        oldroot = sUtils.getRoot(obj=context.active_object)

        if newroot == oldroot:
            log("Object is already root.", 'INFO')
            return {'CANCELLED'}

        # gather model information from old root
        modelprops = eUtils.getProperties(oldroot, category='model')
        oldroot.pose.bones[0].custom_shape = None

        # assign joint resource to oldroot if applicable
        if 'joint/type' in oldroot:
            oldroot.pose.bones[0].custom_shape = ioUtils.getResource(
                ('joint', oldroot['joint/type'])
            )

        eUtils.restructureKinematicTree(newroot)

        # write model information to new root
        newroot.pose.bones[0].custom_shape = ioUtils.getResource(('link', 'root'))
        eUtils.setProperties(newroot, modelprops, category='model')

        # remove model information from old root
        eUtils.removeProperties(oldroot, ['model/*'])
        return {'FINISHED'}


# TODO remove or use? Give it a dev branch
# class SelectErrorOperator(Operator):
#     """Select an object with check errors"""
#     bl_idname = "phobos.select_error"
#     bl_label = "Select Erroneous Object"
#     bl_options = {'REGISTER', 'UNDO'}
#
#     errorObj = EnumProperty(
#         name="Erroneous Objects",
#         items=defs.generateCheckMessages,
#         description="The objects containing errors")
#
#     def execute(self, context):
#         sUtils.selectByName(self.errorObj)
#         for message in vUtils.checkMessages[self.errorObj]:
#             log(message, 'INFO')
#
#         return {'FINISHED'}