Skip to content
Snippets Groups Projects
space_view3d_spacebar_menu.py 48.6 KiB
Newer Older
  • Learn to ignore specific revisions
  •         layout.operator("curve.select_all").action = 'INVERT'
    
            layout.operator("curve.select_random")
    
            layout.operator("curve.select_nth")
    
    
            layout.separator()
    
            layout.operator("curve.select_row")
    
            layout.separator()
    
            layout.operator("curve.select_more")
            layout.operator("curve.select_less")
    
    class VIEW3D_MT_SelectMetaball(bpy.types.Menu):
        bl_label = "Select Menu"
    
        def draw(self, context):
            layout = self.layout
    
            layout.operator("view3d.select_border")
    
            layout.separator()
    
    
            layout.operator("mball.select_all").action = 'TOGGLE'
    
            layout.operator("mball.select_all").action = 'INVERT'
    
            layout.operator("mball.select_random_metaelems")
    
    class VIEW3D_MT_edit_TK(bpy.types.Menu):
    
        bl_label = "Edit Mesh Tools"
    
    
        def draw(self, context):
            layout = self.layout
    
    Campbell Barton's avatar
    Campbell Barton committed
            layout.row()  # XXX, is this needed?
    
    
            layout.operator_context = 'INVOKE_REGION_WIN'
    
    
            layout.menu("VIEW3D_MT_edit_mesh_vertices", icon='VERTEXSEL')
            layout.menu("VIEW3D_MT_edit_mesh_edges", icon='EDGESEL')
            layout.menu("VIEW3D_MT_edit_mesh_faces", icon='FACESEL')
            layout.separator()
            layout.menu("VIEW3D_MT_edit_mesh_normals", icon='META_DATA')
            layout.operator("mesh.loopcut_slide",
    
                            text="Loopcut", icon='EDIT_VEC')
    
    
    
    
    class VIEW3D_MT_edit_multi(bpy.types.Menu):
        bl_label = "Multi Select"
    
        def draw(self, context):
            layout = self.layout
            layout.operator_context = 'INVOKE_REGION_WIN'
    
            layout.separator()
    
            prop = layout.operator("wm.context_set_value", text="Vertex Select",
    
            prop.value = "(True, False, False)"
    
            prop.data_path = "tool_settings.mesh_select_mode"
    
            prop = layout.operator("wm.context_set_value", text="Edge Select",
    
            prop.value = "(False, True, False)"
    
            prop.data_path = "tool_settings.mesh_select_mode"
    
            prop = layout.operator("wm.context_set_value", text="Face Select",
    
            prop.value = "(False, False, True)"
    
            prop.data_path = "tool_settings.mesh_select_mode"
    
            prop = layout.operator("wm.context_set_value",
    
                                   text="Vertex & Edge Select",
                                   icon='EDITMODE_HLT')
    
            prop.value = "(True, True, False)"
            prop.data_path = "tool_settings.mesh_select_mode"
    
    
            prop = layout.operator("wm.context_set_value",
    
                                   text="Vertex & Face Select",
                                   icon='ORTHO')
    
            prop.value = "(True, False, True)"
            prop.data_path = "tool_settings.mesh_select_mode"
    
    
            prop = layout.operator("wm.context_set_value",
    
                                   text="Edge & Face Select",
                                   icon='SNAP_FACE')
    
            prop.value = "(False, True, True)"
            prop.data_path = "tool_settings.mesh_select_mode"
            layout.separator()
    
    
            prop = layout.operator("wm.context_set_value",
    
                                   text="Vertex & Edge & Face Select",
                                   icon='SNAP_VOLUME')
    
            prop.value = "(True, True, True)"
            prop.data_path = "tool_settings.mesh_select_mode"
    
    
    class VIEW3D_MT_editM_Edge(bpy.types.Menu):
        bl_label = "Edges"
    
        def draw(self, context):
            layout = self.layout
            layout.operator_context = 'INVOKE_REGION_WIN'
    
            layout.operator("mesh.mark_seam")
            layout.operator("mesh.mark_seam", text="Clear Seam").clear = True
            layout.separator()
    
            layout.operator("mesh.mark_sharp")
            layout.operator("mesh.mark_sharp", text="Clear Sharp").clear = True
            layout.operator("mesh.extrude_move_along_normals", text="Extrude")
            layout.separator()
    
            layout.operator("mesh.edge_rotate",
    
                            text="Rotate Edge CW").direction = 'CW'
    
            layout.operator("mesh.edge_rotate",
    
                            text="Rotate Edge CCW").direction = 'CCW'
    
            layout.separator()
    
            layout.operator("TFM_OT_edge_slide", text="Edge Slide")
            layout.operator("mesh.loop_multi_select", text="Edge Loop")
            layout.operator("mesh.loop_multi_select", text="Edge Ring").ring = True
            layout.operator("mesh.loop_to_region")
            layout.operator("mesh.region_to_loop")
    
    
    class VIEW3D_MT_EditCurveCtrlpoints(bpy.types.Menu):
        bl_label = "Control Points"
    
        def draw(self, context):
            layout = self.layout
    
            edit_object = context.edit_object
    
            if edit_object.type == 'CURVE':
                layout.operator("transform.transform").mode = 'TILT'
                layout.operator("curve.tilt_clear")
                layout.operator("curve.separate")
    
                layout.separator()
    
                layout.operator_menu_enum("curve.handle_type_set", "type")
    
                layout.separator()
    
                layout.menu("VIEW3D_MT_hook")
    
    
    class VIEW3D_MT_EditCurveSegments(bpy.types.Menu):
        bl_label = "Curve Segments"
    
        def draw(self, context):
            layout = self.layout
    
            layout.operator("curve.subdivide")
            layout.operator("curve.switch_direction")
    
    class VIEW3D_MT_EditCurveSpecials(bpy.types.Menu):
        bl_label = "Specials"
    
        def draw(self, context):
            layout = self.layout
    
            layout.operator("curve.subdivide")
            layout.operator("curve.switch_direction")
            layout.operator("curve.spline_weight_set")
            layout.operator("curve.radius_set")
            layout.operator("curve.smooth")
    
            layout.operator("curve.smooth_weight")
    
            layout.operator("curve.smooth_radius")
    
            layout.operator("curve.smooth_tilt")
    
    
    class VIEW3D_MT_EditArmatureTK(bpy.types.Menu):
        bl_label = "Armature Tools"
    
        def draw(self, context):
            layout = self.layout
    
            # Edit Armature
    
    
            layout.operator("transform.transform",
    
                            text="Scale Envelope Distance").mode = 'BONE_SIZE'
    
            layout.operator("transform.transform",
    
                            text="Scale B-Bone Width").mode = 'BONE_SIZE'
    
            layout.separator()
    
            layout.operator("armature.extrude_move")
    
            layout.operator("armature.extrude_forked")
    
            layout.operator("armature.duplicate_move")
            layout.operator("armature.merge")
            layout.operator("armature.fill")
            layout.operator("armature.delete")
            layout.operator("armature.separate")
    
            layout.separator()
    
    
            layout.operator("armature.subdivide", text="Subdivide")
    
            layout.operator("armature.switch_direction", text="Switch Direction")
    
    class VIEW3D_MT_ArmatureName(bpy.types.Menu):
        bl_label = "Armature Name"
    
        def draw(self, context):
            layout = self.layout
    
            layout.operator_context = 'EXEC_AREA'
    
            layout.operator("armature.autoside_names",
    
                            text="AutoName Left/Right").type = 'XAXIS'
    
            layout.operator("armature.autoside_names",
    
                            text="AutoName Front/Back").type = 'YAXIS'
    
            layout.operator("armature.autoside_names",
    
                            text="AutoName Top/Bottom").type = 'ZAXIS'
    
            layout.operator("armature.flip_names")
            layout.separator()
    
    class VIEW3D_MT_KeyframeMenu(bpy.types.Menu):
        bl_label = "Keyframe Menu"
    
        def draw(self, context):
            layout = self.layout
    
            # Keyframe Bleck
            layout.operator("anim.keyframe_insert_menu",
    
            layout.operator("anim.keyframe_delete_v3d",
    
            layout.operator("anim.keying_set_active_set",
    
                            text="Change Keying Set...")
    
    # Classes for VIEW3D_MT_CursorMenu()
    class VIEW3D_OT_pivot_cursor(bpy.types.Operator):
        "Cursor as Pivot Point"
        bl_idname = "view3d.pivot_cursor"
        bl_label = "Cursor as Pivot Point"
    
    
        @classmethod
        def poll(cls, context):
    
            return bpy.context.space_data.pivot_point != 'CURSOR'
    
        def execute(self, context):
            bpy.context.space_data.pivot_point = 'CURSOR'
            return {'FINISHED'}
    
    class VIEW3D_OT_revert_pivot(bpy.types.Operator):
        "Revert Pivot Point"
        bl_idname = "view3d.revert_pivot"
        bl_label = "Reverts Pivot Point to median"
    
    
        @classmethod
        def poll(cls, context):
    
            return bpy.context.space_data.pivot_point != 'MEDIAN_POINT'
    
        def execute(self, context):
            bpy.context.space_data.pivot_point = 'MEDIAN_POINT'
            # @todo Change this to 'BOUDNING_BOX_CENTER' if needed...
            return{'FINISHED'}
    
    
    class VIEW3D_MT_CursorMenu(bpy.types.Menu):
        bl_label = "Snap Cursor Menu"
    
        def draw(self, context):
    
            layout = self.layout
            layout.operator_context = 'INVOKE_REGION_WIN'
            layout.operator("view3d.snap_cursor_to_selected",
    
            layout.operator("view3d.snap_cursor_to_center",
    
            layout.operator("view3d.snap_cursor_to_grid",
    
            layout.operator("view3d.snap_cursor_to_active",
    
            layout.separator()
            layout.operator("view3d.snap_selected_to_cursor",
    
                            text="Selection to Cursor")
    
            layout.operator("view3d.snap_selected_to_grid",
    
            layout.separator()
            layout.operator("view3d.pivot_cursor",
    
                            text="Set Cursor as Pivot Point")
    
            layout.operator("view3d.revert_pivot",
    
    class VIEW3D_MT_EditCursorMenu(bpy.types.Menu):
        bl_label = "Snap Cursor Menu"
    
        def draw(self, context):
    
            layout = self.layout
            layout.operator_context = 'INVOKE_REGION_WIN'
            layout.operator("view3d.snap_cursor_to_selected",
    
            layout.operator("view3d.snap_cursor_to_center",
    
            layout.operator("view3d.snap_cursor_to_grid",
    
            layout.operator("view3d.snap_cursor_to_active",
    
            layout.separator()
            layout.operator("view3d.snap_selected_to_cursor",
    
                            text="Selection to Cursor")
    
            layout.operator("view3d.snap_selected_to_grid",
    
            layout.separator()
            layout.operator("view3d.pivot_cursor",
    
                            text="Set Cursor as Pivot Point")
    
            layout.operator("view3d.snap_cursor_to_edge_intersection",
    
                            text="Cursor to Edge Intersection")
    
            layout.operator("transform.snap_type", text="Snap Tools",
    
    
    def abs(val):
        if val > 0:
            return val
        return -val
    
    def edgeIntersect(context, operator):
    
        from mathutils.geometry import intersect_line_line
    
    
        if (obj.type != "MESH"):
            operator.report({'ERROR'}, "Object must be a mesh")
            return None
    
        edges = []
    
        verts = mesh.vertices
    
    
        is_editmode = (obj.mode == 'EDIT')
        if is_editmode:
            bpy.ops.object.mode_set(mode='OBJECT')
    
            if e.select:
    
                if len(edges) > 2:
                    break
    
    
        if is_editmode:
            bpy.ops.object.mode_set(mode='EDIT')
    
            operator.report({'ERROR'},
    
                            "Operator requires exactly 2 edges to be selected")
    
        line = intersect_line_line(verts[edges[0].vertices[0]].co,
                                   verts[edges[0].vertices[1]].co,
                                   verts[edges[1].vertices[0]].co,
                                   verts[edges[1].vertices[1]].co)
    
        if line is None:
    
            operator.report({'ERROR'}, "Selected edges do not intersect")
    
        point = line[0].lerp(line[1], 0.5)
    
        context.scene.cursor_location = obj.matrix_world * point
    
    
    class VIEW3D_OT_CursorToEdgeIntersection(bpy.types.Operator):
    
        "Finds the mid-point of the shortest distance between two edges"
    
        bl_idname = "view3d.snap_cursor_to_edge_intersection"
        bl_label = "Cursor to Edge Intersection"
    
    
        @classmethod
        def poll(cls, context):
    
            obj = context.active_object
            return obj != None and obj.type == 'MESH'
    
        def execute(self, context):
            edgeIntersect(context, self)
            return {'FINISHED'}
    
    
    class VIEW3D_MT_undoS(bpy.types.Menu):
        bl_label = "Undo/Redo"
    
        def draw(self, context):
            layout = self.layout
            layout.operator_context = 'INVOKE_REGION_WIN'
            layout.operator("ed.undo", icon='TRIA_LEFT')
            layout.operator("ed.redo", icon='TRIA_RIGHT')
    
    def register():
    
        wm = bpy.context.window_manager
    
        kc = wm.keyconfigs.addon
        if kc:
            km = kc.keymaps.new(name='3D View', space_type='VIEW_3D')
            kmi = km.keymap_items.new('wm.call_menu', 'SPACE', 'PRESS')
            kmi.properties.name = "VIEW3D_MT_Space_Dynamic_Menu"
    
        wm = bpy.context.window_manager
    
        kc = wm.keyconfigs.addon
        if kc:
    
            km = kc.keymaps['3D View']
    
            for kmi in km.keymap_items:
                if kmi.idname == 'wm.call_menu':
                    if kmi.properties.name == "VIEW3D_MT_Space_Dynamic_Menu":
                        km.keymap_items.remove(kmi)
                        break
    
    
    if __name__ == "__main__":
        register()