Here are the examples of the python api bpy.ops.object.parent_set taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
4 Examples
4
Example 1
Project: coa_tools Source File: functions.py
def create_armature_parent(context):
sprite = context.active_object
armature = get_armature(get_sprite_object(sprite))
armature.select = True
context.scene.objects.active = armature
bpy.ops.object.parent_set(type='ARMATURE_NAME')
context.scene.objects.active = sprite
3
Example 2
def setParent(obj, parent):
ho = obj.hide
hp = parent.hide
obj.hide = False
parent.hide = False
select_object(parent)
obj.select = True
bpy.ops.object.parent_set(type='OBJECT', xmirror=False, keep_transform=False)
obj.hide = ho
parent.hide = hp
2
Example 3
Project: phobos Source File: links.py
def deriveLinkfromObject(obj, scale=0.2, parenting=True, parentobjects=False, namepartindices=[], separator='_', prefix='link'):
"""Derives a link from an object that defines a joint through its position, orientation and parent-child relationships.
:param obj: The object you want to derive your link from.
:type obj: bpy_types.Object
:param scale: The scale you want to apply to the link.
:type scale: float
:param parenting: Whether you want to automate the parenting of the new link or not.
:type parenting: bool.
:param parentobjects: Whether you want to parent all the objects to the new link or not.
:type parentobjects: bool.
:param namepartindices: Parts of the objects name you want to reuse in the links name.
:type namepartindices: list with two elements.
:param separator: The separator you want to use to separate the links name with. Its '_' per default
:type separator: str
:param prefix: The prefix you want to use for the new links name. Its 'link' per default.
:type prefix: str
"""
print('Deriving link from', namingUtils.getObjectName(obj))
nameparts = namingUtils.getObjectName(obj).split('_')
rotation = obj.matrix_world.to_euler()
if 'invertAxis' in obj and obj['invertAxis'] == 1:
rotation.x += math.pi if rotation.x < 0 else -math.pi
tmpname = namingUtils.getObjectName(obj)
if namepartindices:
try:
tmpname = separator.join([nameparts[p] for p in namepartindices])
except IndexError:
print('Wrong name segment indices given for obj', namingUtils.getObjectName(obj))
if prefix != '':
tmpname = prefix + separator + tmpname
if tmpname == namingUtils.getObjectName(obj):
obj.name += '*'
link = createLink(scale, obj.matrix_world.to_translation(), obj.matrix_world.to_euler(), tmpname)
if parenting:
if obj.parent:
selectionUtils.selectObjects([link, obj.parent], True, 1)
if obj.parent.phobostype == 'link':
bpy.ops.object.parent_set(type='BONE_RELATIVE')
else:
bpy.ops.object.parent_set(type='OBJECT')
children = selectionUtils.getImmediateChildren(obj)
if parentobjects:
children.append(obj)
for child in children:
selectionUtils.selectObjects([child], True, 0)
bpy.ops.object.parent_clear(type='CLEAR_KEEP_TRANSFORM')
selectionUtils.selectObjects([child, link], True, 1)
bpy.ops.object.parent_set(type='BONE_RELATIVE')
0
Example 4
def set_weights(self,context,obj):
self.set_waits = True
bone_data = []
orig_armature = context.active_object
### remove bone vertex_groups
for weight in obj.vertex_groups:
if weight.name in orig_armature.data.bones:
obj.vertex_groups.remove(weight)
###
use_deform = []
selected_bones = []
for i,bone in enumerate(orig_armature.data.edit_bones):
if bone.select and (bone.select_head or bone.select_tail):
selected_bones.append(bone)
use_deform.append(orig_armature.data.bones[i].use_deform)
if bone.select and (bone.select_head or bone.select_tail):
orig_armature.data.bones[i].use_deform = True
else:
orig_armature.data.bones[i].use_deform = False
orig_armature.select = True
obj.select = True
obj_orig_location = Vector(obj.location)
obj.location[1] = 0
bpy.ops.object.parent_set(type='ARMATURE_AUTO')
obj.location = obj_orig_location
for i,bone in enumerate(orig_armature.data.edit_bones):
orig_armature.data.bones[i].use_deform = use_deform[i]
i = 0
for modifier in obj.modifiers:
if modifier.type == "ARMATURE":
i += 1
if i > 1:
obj.modifiers.remove(obj.modifiers[len(obj.modifiers)-1])
for modifier in obj.modifiers:
if modifier.type == "ARMATURE":
modifier.object = orig_armature
obj.parent = orig_armature
orig_armature.select = True
context.scene.objects.active = orig_armature
obj.select = False
bpy.ops.object.mode_set(mode='EDIT')
self.set_waits = False