Skip to content

Instantly share code, notes, and snippets.

@sambler
Created January 11, 2016 11:14
Show Gist options
  • Save sambler/98fed42b3862bf04ba96 to your computer and use it in GitHub Desktop.
Save sambler/98fed42b3862bf04ba96 to your computer and use it in GitHub Desktop.
# made in response to
# http://blender.stackexchange.com/q/44721/935
# render frame ranges for each nla strip with only the one strip active
output_dir = '//renders/'
scene = bpy.context.scene
# make a list of strips used in the NLA
# strips are found in -
# object.animation_data.nla_tracks[TrackName].strips[stripName]
nla_strips = []
for obj in scene.objects:
if obj.animation_data and obj.animation_data.nla_tracks:
for track in obj.animation_data.nla_tracks:
for strip in track.strips:
nla_strips.append((strip,strip.mute))
strip.mute = True
# save to restore restore
orig_frame_start = scene.frame_start
orig_frame_end = scene.frame_end
orig_filepath = scene.render.filepath
# render each strip
for strip in nla_strips:
scene.render.filepath = output_dir + strip[0].name + '/'
scene.frame_start = strip[0].frame_start
scene.frame_end = strip[0].frame_end
strip[0].mute = False
bpy.ops.render.render(animation=True)
strip[0].mute = True
# restore changes we made
scene.frame_start = orig_frame_start
scene.frame_end = orig_frame_end
scene.render.filepath = orig_filepath
for strip in nla_strips:
strip[0].mute = strip[1]
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment