select parent/child in object mode with [] keys, like pose mode.
also needed to extend the RNA api to allow C to set enums without meaningful values.
This commit is contained in:
@@ -96,6 +96,48 @@ class SelectCamera(bpy.types.Operator):
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
class SelectHierarchy(bpy.types.Operator):
|
||||
'''Select object relative to the active objects position in the hierarchy'''
|
||||
bl_idname = "object.select_hierarchy"
|
||||
bl_label = "Select Hierarchy"
|
||||
bl_register = True
|
||||
bl_undo = True
|
||||
|
||||
direction = EnumProperty(items=(
|
||||
('PARENT', "Parent", ""),
|
||||
('CHILD', "Child", "")),
|
||||
name="Direction",
|
||||
description="Direction to select in the hierarchy",
|
||||
default='PARENT')
|
||||
|
||||
extend = BoolProperty(name="Extend", description="Extend the existing selection", default=False)
|
||||
|
||||
def poll(self, context):
|
||||
return context.object
|
||||
|
||||
def execute(self, context):
|
||||
obj = context.object
|
||||
if self.properties.direction == 'PARENT':
|
||||
parent = obj.parent
|
||||
if not parent:
|
||||
return {'CANCELLED'}
|
||||
obj_act = parent
|
||||
else:
|
||||
children = obj.children
|
||||
if len(children) != 1:
|
||||
return {'CANCELLED'}
|
||||
obj_act = children[0]
|
||||
|
||||
if not self.properties.extend:
|
||||
# obj.selected = False
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
|
||||
obj_act.selected = True
|
||||
context.scene.objects.active = obj_act
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
class SubdivisionSet(bpy.types.Operator):
|
||||
'''Sets a Subdivision Surface Level (1-5)'''
|
||||
|
||||
@@ -471,6 +513,7 @@ class MakeDupliFace(bpy.types.Operator):
|
||||
classes = [
|
||||
SelectPattern,
|
||||
SelectCamera,
|
||||
SelectHierarchy,
|
||||
SubdivisionSet,
|
||||
ShapeTransfer,
|
||||
JoinUVs,
|
||||
|
||||
@@ -289,6 +289,18 @@ void ED_keymap_object(wmKeyConfig *keyconf)
|
||||
WM_keymap_add_item(keymap, "OBJECT_OT_select_grouped", GKEY, KM_PRESS, KM_SHIFT, 0);
|
||||
WM_keymap_add_item(keymap, "OBJECT_OT_select_mirror", MKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
|
||||
|
||||
kmi= WM_keymap_add_item(keymap, "OBJECT_OT_select_hierarchy", LEFTBRACKETKEY, KM_PRESS, 0, 0);
|
||||
RNA_enum_set_identifier(kmi->ptr, "direction", "PARENT");
|
||||
kmi= WM_keymap_add_item(keymap, "OBJECT_OT_select_hierarchy", LEFTBRACKETKEY, KM_PRESS, KM_SHIFT, 0);
|
||||
RNA_enum_set_identifier(kmi->ptr, "direction", "PARENT");
|
||||
RNA_boolean_set(kmi->ptr, "extend", 1);
|
||||
|
||||
kmi= WM_keymap_add_item(keymap, "OBJECT_OT_select_hierarchy", RIGHTBRACKETKEY, KM_PRESS, 0, 0);
|
||||
RNA_enum_set_identifier(kmi->ptr, "direction", "CHILD");
|
||||
kmi= WM_keymap_add_item(keymap, "OBJECT_OT_select_hierarchy", RIGHTBRACKETKEY, KM_PRESS, KM_SHIFT, 0);
|
||||
RNA_enum_set_identifier(kmi->ptr, "direction", "CHILD");
|
||||
RNA_boolean_set(kmi->ptr, "extend", 1);
|
||||
|
||||
WM_keymap_verify_item(keymap, "OBJECT_OT_parent_set", PKEY, KM_PRESS, KM_CTRL, 0);
|
||||
WM_keymap_verify_item(keymap, "OBJECT_OT_parent_no_inverse_set", PKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
|
||||
WM_keymap_verify_item(keymap, "OBJECT_OT_parent_clear", PKEY, KM_PRESS, KM_ALT, 0);
|
||||
|
||||
@@ -809,6 +809,7 @@ void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
|
||||
|
||||
int RNA_enum_get(PointerRNA *ptr, const char *name);
|
||||
void RNA_enum_set(PointerRNA *ptr, const char *name, int value);
|
||||
void RNA_enum_set_identifier(PointerRNA *ptr, const char *name, const char *id);
|
||||
int RNA_enum_is_equal(struct bContext *C, PointerRNA *ptr, const char *name, const char *enumname);
|
||||
|
||||
/* lower level functions that donr use a PointerRNA */
|
||||
|
||||
@@ -3295,6 +3295,20 @@ void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
|
||||
printf("RNA_enum_set: %s.%s not found.\n", ptr->type->identifier, name);
|
||||
}
|
||||
|
||||
void RNA_enum_set_identifier(PointerRNA *ptr, const char *name, const char *id)
|
||||
{
|
||||
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
|
||||
|
||||
if(prop) {
|
||||
int value;
|
||||
if(RNA_property_enum_value(NULL, ptr, prop, id, &value))
|
||||
RNA_property_enum_set(ptr, prop, value);
|
||||
else
|
||||
printf("RNA_enum_set_identifier: %s.%s has no enum id '%s'.\n", ptr->type->identifier, name, id);
|
||||
} else
|
||||
printf("RNA_enum_set_identifier: %s.%s not found.\n", ptr->type->identifier, name);
|
||||
}
|
||||
|
||||
int RNA_enum_is_equal(bContext *C, PointerRNA *ptr, const char *name, const char *enumname)
|
||||
{
|
||||
PropertyRNA *prop= RNA_struct_find_property(ptr, name);
|
||||
|
||||
Reference in New Issue
Block a user