Skip to main content
image
Source Link
brockmann
  • 12.8k
  • 4
  • 51
  • 94

Basic example using a circle based on Cegaton's setup fromCegaton's setup from here.

enter image description here

Add the primitives, create variables per object and constraint to store the referencesa camera. AddAssign each object reference to a new variable and add a Follow Path and Track To constraint using Object.constraints.new() method and. Finally set all the constraint properties of the constraints, eg. assign the object referencevariables to the FollowPath.target or set TrackTo.up_axis to 'UP_Y':

import bpy

# Add Suzanne
bpy.ops.mesh.primitive_monkey_add(size=2)
suzanne = bpy.context.object

# Add circleCircle
bpy.ops.curve.primitive_bezier_circle_add(radius=10)
circle = bpy.context.object

# Add cameraCamera
bpy.ops.object.camera_add(location=(0, 0, 0))
camera = bpy.context.object

# Follow Path Constraint
fp_constraint = camera.constraints.new('FOLLOW_PATH')
fp_constraint.target = circle

# Animate Button
bpy.ops.constraint.followpath_path_animate({
    'constraint':camera.constraints["Follow Path"]
    }, constraint='Follow Path')

# Track -To Constraint
tt_constraint = camera.constraints.new('TRACK_TO')
tt_constraint.target = suzanne
tt_constraint.up_axis = 'UP_Y'
tt_constraint.track_axis = 'TRACK_NEGATIVE_Z'

Basic example based on Cegaton's setup from here. Add the primitives, create variables per object and constraint to store the references. Add a Follow Path and Track To constraint using Object.constraints.new() method and set the properties of the constraints eg. assign the object reference to the FollowPath.target or set TrackTo.up_axis to 'UP_Y':

import bpy

# Add Suzanne
bpy.ops.mesh.primitive_monkey_add(size=2)
suzanne = bpy.context.object

# Add circle
bpy.ops.curve.primitive_bezier_circle_add(radius=10)
circle = bpy.context.object

# Add camera
bpy.ops.object.camera_add(location=(0, 0, 0))
camera = bpy.context.object

# Follow Path Constraint
fp_constraint = camera.constraints.new('FOLLOW_PATH')
fp_constraint.target = circle

# Animate Button
bpy.ops.constraint.followpath_path_animate({
    'constraint':camera.constraints["Follow Path"]
    }, constraint='Follow Path')

# Track To Constraint
tt_constraint = camera.constraints.new('TRACK_TO')
tt_constraint.target = suzanne
tt_constraint.up_axis = 'UP_Y'
tt_constraint.track_axis = 'TRACK_NEGATIVE_Z'

Basic example using a circle based on Cegaton's setup from here.

enter image description here

Add the primitives and a camera. Assign each object reference to a new variable and add a Follow Path and Track To constraint using Object.constraints.new() method. Finally set all the constraint properties, eg. assign the variables to the FollowPath.target or set TrackTo.up_axis to 'UP_Y':

import bpy

# Add Suzanne
bpy.ops.mesh.primitive_monkey_add(size=2)
suzanne = bpy.context.object

# Add Circle
bpy.ops.curve.primitive_bezier_circle_add(radius=10)
circle = bpy.context.object

# Add Camera
bpy.ops.object.camera_add(location=(0, 0, 0))
camera = bpy.context.object

# Follow Path Constraint
fp_constraint = camera.constraints.new('FOLLOW_PATH')
fp_constraint.target = circle

# Animate Button
bpy.ops.constraint.followpath_path_animate({
    'constraint':camera.constraints["Follow Path"]
    }, constraint='Follow Path')

# Track-To Constraint
tt_constraint = camera.constraints.new('TRACK_TO')
tt_constraint.target = suzanne
tt_constraint.up_axis = 'UP_Y'
tt_constraint.track_axis = 'TRACK_NEGATIVE_Z'
Source Link
brockmann
  • 12.8k
  • 4
  • 51
  • 94

Basic example based on Cegaton's setup from here. Add the primitives, create variables per object and constraint to store the references. Add a Follow Path and Track To constraint using Object.constraints.new() method and set the properties of the constraints eg. assign the object reference to the FollowPath.target or set TrackTo.up_axis to 'UP_Y':

import bpy

# Add Suzanne
bpy.ops.mesh.primitive_monkey_add(size=2)
suzanne = bpy.context.object

# Add circle
bpy.ops.curve.primitive_bezier_circle_add(radius=10)
circle = bpy.context.object

# Add camera
bpy.ops.object.camera_add(location=(0, 0, 0))
camera = bpy.context.object

# Follow Path Constraint
fp_constraint = camera.constraints.new('FOLLOW_PATH')
fp_constraint.target = circle

# Animate Button
bpy.ops.constraint.followpath_path_animate({
    'constraint':camera.constraints["Follow Path"]
    }, constraint='Follow Path')

# Track To Constraint
tt_constraint = camera.constraints.new('TRACK_TO')
tt_constraint.target = suzanne
tt_constraint.up_axis = 'UP_Y'
tt_constraint.track_axis = 'TRACK_NEGATIVE_Z'