将所选对象的约束复制到选择的其他对象。
bpy.ops.constraint.copy_to_selected()
无参数。
{'FINISHED'}
: 表示函数执行成功。无异常抛出。
# 复制约束到选择的其他对象
import bpy
# 获取当前选中的对象的约束
activeobj = bpy.context.active_object
activeconstraints = activeobj.constraints
# 选择需要复制约束的对象
selectedobjs = bpy.context.selected_objects
selectedobjs.remove(activeobj)
# 将约束复制到选择的其他对象
for obj in selectedobjs:
for constraint in activeconstraints:
new_constraint = obj.constraints.new(type=constraint.type)
new_constraint.name = constraint.name
new_constraint.influence = constraint.influence
new_constraint.mute = constraint.mute
new_constraint.show_expanded = constraint.show_expanded
new_constraint.use_bone_relative_path = constraint.use_bone_relative_path
new_constraint.use_motion_extrapolate = constraint.use_motion_extrapolate
new_constraint.use_peg_motion = constraint.use_peg_motion
new_constraint.use_rotation_mode_enu = constraint.use_rotation_mode_enu
new_constraint.use_scale_x = constraint.use_scale_x
new_constraint.use_scale_y = constraint.use_scale_y
new_constraint.use_scale_z = constraint.use_scale_z
new_constraint.use_stretch_offset = constraint.use_stretch_offset
new_constraint.target_space = constraint.target_space
new_constraint.owner_space = constraint.owner_space
new_constraint.subtarget = constraint.subtarget
new_constraint.target = constraint.target
new_constraint.target_matrix = constraint.target_matrix
new_constraint.inverse_matrix = constraint.inverse_matrix