0
$\begingroup$

I am rendering all cameras, all collections and all actions. When I change action, the render still renders the first action, not the new action.

Here is my render code:

def performRender(outputPath, actions):
    print("Performing render...")

    scene = bpy.data.scenes[0]

    for collection in bpy.context.scene.collection.objects:
        collection.hide_render = False

        collectionName = collection.name.lower()

        for camera in scene.objects:
            if camera.type == "CAMERA":
                scene.camera = camera

                for action in actions:
                    frameStart = int(action.frame_range[0])
                    frameEnd = int(action.frame_range[1])
                    frameStep = 1

                    if collection.animation_data is None:
                        collection.animation_data_create()

                    # the problem seems to be here
                    # the first action set renders fine,
                    # but any other actions are not rendered,
                    # only the first action is
                    collection.animation_data.action = action

                    for currentFrame in range(frameStart, frameEnd + 1, frameStep):
                        scene.frame_set(currentFrame)

                        scene.render.filepath = os.path.join(outputPath, f"character_{collectionName}_{action.name}_{camera.name}_{currentFrame}.png")

                        bpy.ops.render.render(write_still = True)

        collection.hide_render = True

    print("Performed render.")

Here is how I am loading the actions:

def setupCollections(characterPath):
    collections = bpy.context.scene.collection

    with bpy.data.libraries.load(characterPath) as (dataFrom, dataTo):
        dataTo.collections = dataFrom.collections
        dataTo.scenes = dataFrom.scenes
        dataTo.actions = dataFrom.actions

    for collection in dataTo.collections:
        instance = bpy.data.objects.new(collection.name, None)
        instance.instance_type = "COLLECTION"
        instance.instance_collection = collection
        instance.hide_render = True
        
        collections.objects.link(instance)

    return dataTo.actions

When I save and load the resulting .blend file, I can see the actions have been created, but they both affect the models in the same way. I wonder if when the actions are loaded, they are the same, instead of different?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.