Skip to main content
update answer for blender 3
Source Link
gandalf3
  • 158.3k
  • 60
  • 612
  • 1.1k

You need to override the context. AFAIK setting area.type does not work.

Baking cloth is very similaroverride the context for the operator to baking fluid or smokework.
This question has already been asked for smoke and fluid, so I will quote one of the answerssimilar to this answer on baking fluid or smoke here:

Baking smoke is very similar to baking fluid, so I will quote brecht's answer:

It's a bit more complicated than it could be because fluid simulating baking is only exposed as an operator. That means it expects an active object in the context, which is usually provided by the user interface that is not available in background mode.

However, it is possible to override context manually, see the api docs.

So for a smoke simulation:

import bpy

for scene in bpy.data.scenes:
    for object in scene.objects:
        for modifier in object.modifiers:
            if modifier.type == 'SMOKE':
                if modifier.smoke_type == 'DOMAIN':
                    override = {'scene': scene, 'active_object': object, 'point_cache': modifier.domain_settings.point_cache}
                    bpy.ops.ptcache.bake(override, bake=True)
                    break

This will bake the selected cache for all domain objects in the file.

Using the simple script below which is adapted from the script in the above quote (which is in turn adapted from brecht's answer about baking fluid), you can bake the cloth cache for every object in the file which has a cloth modifier like this:

import bpy

for scene in bpy.data.scenes:
    for object in scene.objects:
        for modifier in object.modifiers:
            if modifier.type == 'CLOTH':
                overridewith =bpy.context.temp_override(scene=scene,
 {'scene': scene, 'active_object': object, 'point_cache': modifier.point_cache}
                bpy.ops.ptcache.bake(override                         active_object=object, 
 bake=True                                              point_cache=modifier.point_cache):
                break    bpy.ops.ptcache.bake(bake=True)

You need to override the context. AFAIK setting area.type does not work.

Baking cloth is very similar to baking fluid or smoke.
This question has already been asked for smoke and fluid, so I will quote one of the answers here:

Baking smoke is very similar to baking fluid, so I will quote brecht's answer:

It's a bit more complicated than it could be because fluid simulating baking is only exposed as an operator. That means it expects an active object in the context, which is usually provided by the user interface that is not available in background mode.

However, it is possible to override context manually, see the api docs.

So for a smoke simulation:

import bpy

for scene in bpy.data.scenes:
    for object in scene.objects:
        for modifier in object.modifiers:
            if modifier.type == 'SMOKE':
                if modifier.smoke_type == 'DOMAIN':
                    override = {'scene': scene, 'active_object': object, 'point_cache': modifier.domain_settings.point_cache}
                    bpy.ops.ptcache.bake(override, bake=True)
                    break

This will bake the selected cache for all domain objects in the file.

Using the simple script below which is adapted from the script in the above quote (which is in turn adapted from brecht's answer about baking fluid), you can bake the cloth cache for every object in the file which has a cloth modifier:

import bpy

for scene in bpy.data.scenes:
    for object in scene.objects:
        for modifier in object.modifiers:
            if modifier.type == 'CLOTH':
                override = {'scene': scene, 'active_object': object, 'point_cache': modifier.point_cache}
                bpy.ops.ptcache.bake(override, bake=True)
                break 

You need to override the context for the operator to work. similar to this answer on baking fluid or smoke, you can bake the cloth cache for every object in the file which has a cloth modifier like this:

import bpy

for scene in bpy.data.scenes:
    for object in scene.objects:
        for modifier in object.modifiers:
            if modifier.type == 'CLOTH':
                with bpy.context.temp_override(scene=scene,
                                               active_object=object, 
                                               point_cache=modifier.point_cache):
                    bpy.ops.ptcache.bake(bake=True)
replaced http://blender.stackexchange.com/ with https://blender.stackexchange.com/
Source Link

You need to override the context. AFAIK setting area.type does not work.

Baking cloth is very similar to baking fluid or smoke.
This question has already been asked for smoke and fluid, so I will quote one of the answersone of the answers here:

Baking smoke is very similar to baking fluid, so I will quote brecht's answerbrecht's answer:

It's a bit more complicated than it could be because fluid simulating baking is only exposed as an operator. That means it expects an active object in the context, which is usually provided by the user interface that is not available in background mode.

However, it is possible to override context manually, see the api docs.

So for a smoke simulation:

import bpy

for scene in bpy.data.scenes:
    for object in scene.objects:
        for modifier in object.modifiers:
            if modifier.type == 'SMOKE':
                if modifier.smoke_type == 'DOMAIN':
                    override = {'scene': scene, 'active_object': object, 'point_cache': modifier.domain_settings.point_cache}
                    bpy.ops.ptcache.bake(override, bake=True)
                    break

This will bake the selected cache for all domain objects in the file.

Using the simple script below which is adapted from the script in the above quote (which is in turn adapted from brecht's answerbrecht's answer about baking fluid), you can bake the cloth cache for every object in the file which has a cloth modifier:

import bpy

for scene in bpy.data.scenes:
    for object in scene.objects:
        for modifier in object.modifiers:
            if modifier.type == 'CLOTH':
                override = {'scene': scene, 'active_object': object, 'point_cache': modifier.point_cache}
                bpy.ops.ptcache.bake(override, bake=True)
                break 

You need to override the context. AFAIK setting area.type does not work.

Baking cloth is very similar to baking fluid or smoke.
This question has already been asked for smoke and fluid, so I will quote one of the answers here:

Baking smoke is very similar to baking fluid, so I will quote brecht's answer:

It's a bit more complicated than it could be because fluid simulating baking is only exposed as an operator. That means it expects an active object in the context, which is usually provided by the user interface that is not available in background mode.

However, it is possible to override context manually, see the api docs.

So for a smoke simulation:

import bpy

for scene in bpy.data.scenes:
    for object in scene.objects:
        for modifier in object.modifiers:
            if modifier.type == 'SMOKE':
                if modifier.smoke_type == 'DOMAIN':
                    override = {'scene': scene, 'active_object': object, 'point_cache': modifier.domain_settings.point_cache}
                    bpy.ops.ptcache.bake(override, bake=True)
                    break

This will bake the selected cache for all domain objects in the file.

Using the simple script below which is adapted from the script in the above quote (which is in turn adapted from brecht's answer about baking fluid), you can bake the cloth cache for every object in the file which has a cloth modifier:

import bpy

for scene in bpy.data.scenes:
    for object in scene.objects:
        for modifier in object.modifiers:
            if modifier.type == 'CLOTH':
                override = {'scene': scene, 'active_object': object, 'point_cache': modifier.point_cache}
                bpy.ops.ptcache.bake(override, bake=True)
                break 

You need to override the context. AFAIK setting area.type does not work.

Baking cloth is very similar to baking fluid or smoke.
This question has already been asked for smoke and fluid, so I will quote one of the answers here:

Baking smoke is very similar to baking fluid, so I will quote brecht's answer:

It's a bit more complicated than it could be because fluid simulating baking is only exposed as an operator. That means it expects an active object in the context, which is usually provided by the user interface that is not available in background mode.

However, it is possible to override context manually, see the api docs.

So for a smoke simulation:

import bpy

for scene in bpy.data.scenes:
    for object in scene.objects:
        for modifier in object.modifiers:
            if modifier.type == 'SMOKE':
                if modifier.smoke_type == 'DOMAIN':
                    override = {'scene': scene, 'active_object': object, 'point_cache': modifier.domain_settings.point_cache}
                    bpy.ops.ptcache.bake(override, bake=True)
                    break

This will bake the selected cache for all domain objects in the file.

Using the simple script below which is adapted from the script in the above quote (which is in turn adapted from brecht's answer about baking fluid), you can bake the cloth cache for every object in the file which has a cloth modifier:

import bpy

for scene in bpy.data.scenes:
    for object in scene.objects:
        for modifier in object.modifiers:
            if modifier.type == 'CLOTH':
                override = {'scene': scene, 'active_object': object, 'point_cache': modifier.point_cache}
                bpy.ops.ptcache.bake(override, bake=True)
                break 
deleted 192 characters in body
Source Link
gandalf3
  • 158.3k
  • 60
  • 612
  • 1.1k

You need to override the context. AFAIK setting area.type does not work.

Baking cloth is very similar to baking fluid or smoke.
This question has already been asked for smoke and fluid, so I will quote one of the answers here:

Baking smoke is very similar to baking fluid, so I will quote brecht's answer:

It's a bit more complicated than it could be because fluid simulating baking is only exposed as an operator. That means it expects an active object in the context, which is usually provided by the user interface that is not available in background mode.

However, it is possible to override context manually, see the api docs.

So for a smoke simulation:

import bpy

for scene in bpy.data.scenes:
    for object in scene.objects:
        for modifier in object.modifiers:
            if modifier.type == 'SMOKE':
                if modifier.smoke_type == 'DOMAIN':
                    override = {'scene': scene, 'active_object': object, 'point_cache': modifier.domain_settings.point_cache}
                    bpy.ops.ptcache.bake(override, bake=True)
                    break

This will bake the selected cache for all domain objects in the file.

You can then run this python script in blender with

blender --background /path/to/file.blend --python /path/to/script.py

Or the short way:

blender -b /path/to/file.blend -P /path/to/script.py

Using the simple script below which is adapted from the script in the above quote (which is in turn adapted from Brecht'sbrecht's answer about baking fluid), you can bake the cloth cache for every object in the file which has a cloth modifier:

import bpy

for scene in bpy.data.scenes:
    for object in scene.objects:
        for modifier in object.modifiers:
            if modifier.type == 'CLOTH':
                override = {'scene': scene, 'active_object': object, 'point_cache': modifier.point_cache}
                bpy.ops.ptcache.bake(override, bake=True)
                break 

You need to override the context. AFAIK setting area.type does not work.

Baking cloth is very similar to baking fluid or smoke.
This question has already been asked for smoke and fluid, so I will quote one of the answers here:

Baking smoke is very similar to baking fluid, so I will quote brecht's answer:

It's a bit more complicated than it could be because fluid simulating baking is only exposed as an operator. That means it expects an active object in the context, which is usually provided by the user interface that is not available in background mode.

However, it is possible to override context manually, see the api docs.

So for a smoke simulation:

import bpy

for scene in bpy.data.scenes:
    for object in scene.objects:
        for modifier in object.modifiers:
            if modifier.type == 'SMOKE':
                if modifier.smoke_type == 'DOMAIN':
                    override = {'scene': scene, 'active_object': object, 'point_cache': modifier.domain_settings.point_cache}
                    bpy.ops.ptcache.bake(override, bake=True)
                    break

This will bake the selected cache for all domain objects in the file.

You can then run this python script in blender with

blender --background /path/to/file.blend --python /path/to/script.py

Or the short way:

blender -b /path/to/file.blend -P /path/to/script.py

Using the simple script below which is adapted the script in the above quote (which is in turn adapted from Brecht's answer about baking fluid), you bake the cloth cache for every object in the file:

import bpy

for scene in bpy.data.scenes:
    for object in scene.objects:
        for modifier in object.modifiers:
            if modifier.type == 'CLOTH':
                override = {'scene': scene, 'active_object': object, 'point_cache': modifier.point_cache}
                bpy.ops.ptcache.bake(override, bake=True)
                break 

You need to override the context. AFAIK setting area.type does not work.

Baking cloth is very similar to baking fluid or smoke.
This question has already been asked for smoke and fluid, so I will quote one of the answers here:

Baking smoke is very similar to baking fluid, so I will quote brecht's answer:

It's a bit more complicated than it could be because fluid simulating baking is only exposed as an operator. That means it expects an active object in the context, which is usually provided by the user interface that is not available in background mode.

However, it is possible to override context manually, see the api docs.

So for a smoke simulation:

import bpy

for scene in bpy.data.scenes:
    for object in scene.objects:
        for modifier in object.modifiers:
            if modifier.type == 'SMOKE':
                if modifier.smoke_type == 'DOMAIN':
                    override = {'scene': scene, 'active_object': object, 'point_cache': modifier.domain_settings.point_cache}
                    bpy.ops.ptcache.bake(override, bake=True)
                    break

This will bake the selected cache for all domain objects in the file.

Using the simple script below which is adapted from the script in the above quote (which is in turn adapted from brecht's answer about baking fluid), you can bake the cloth cache for every object in the file which has a cloth modifier:

import bpy

for scene in bpy.data.scenes:
    for object in scene.objects:
        for modifier in object.modifiers:
            if modifier.type == 'CLOTH':
                override = {'scene': scene, 'active_object': object, 'point_cache': modifier.point_cache}
                bpy.ops.ptcache.bake(override, bake=True)
                break 
added 290 characters in body
Source Link
gandalf3
  • 158.3k
  • 60
  • 612
  • 1.1k
Loading
added 414 characters in body
Source Link
gandalf3
  • 158.3k
  • 60
  • 612
  • 1.1k
Loading
Source Link
gandalf3
  • 158.3k
  • 60
  • 612
  • 1.1k
Loading