I want to manipulate options like Disk Cache with python:
Any Ideas?
You can access all 'cloth properties' of an object by referencing the cloth modifier:
>>> bpy.data.objects['Cube'].modifiers['Cloth'].settings.mass
>>> 0.30000001192092896
>>> bpy.data.objects['Cube'].modifiers['Cloth'].point_cache.frame_start
>>> 0
>>> bpy.data.objects['Cube'].modifiers['Cloth'].point_cache.use_disk_cache
>>> False
To find the desired property you can use python's dir() method, which returns a list of valid attributes for e.g.:
modifiers['ClothModifierName'].collision_settingsmodifiers['ClothModifierName'].settingsmodifiers['ClothModifierName'].point_cachewhich also contain all the relevant attributes.
Setting Cache attributes like use_disk_cache and frame_start of the active object:
>>> obj = bpy.context.active_object
>>> obj.modifiers['Cloth'].point_cache.use_disk_cache = True
>>> obj.modifiers['Cloth'].point_cache.use_disk_cache
>>> True
>>> obj.modifiers['Cloth'].point_cache.frame_start = 10
>>> obj.modifiers['Cloth'].point_cache.frame_start
>>> 10
To avoid assignment errors you can check the respective 'property type' by using python's built-in type() method:
>>> type(bpy.data.objects['Cube'].modifiers['Cloth'].point_cache.use_disk_cache)
>>> <class 'bool'>
>>> type(bpy.data.objects['Cube'].modifiers['Cloth'].settings.mass)
>>> <class 'float'>
In order to set the attributes for multiple 'cloth objects' I'd suggest to check if the respective object has modifiers (also see this answer: Check if active object has a modifier) then iterate through the modifier list and check whether the type is correct:
import bpy
get objects in selection
for obj in bpy.context.selected_objects:
# check if object has modifiers
if obj.modifiers:
print ("has modifiers")
for modifier in obj.modifiers:
# if object has cloth modifier
if modifier.type == "CLOTH":
# use disk cache attribute
print (modifier.point_cache.use_disk_cache)
# set the attribute
modifier.point_cache.use_disk_cache = True
# mass attribute
print (modifier.settings.mass)
# set the attribute
modifier.settings.mass = 1.0
If you need to bake the simulation via python, see this answer: Setting the context for cloth bake