I want to manipulate options like Disk Cache with python:

enter image description here

Any Ideas?

  • $\begingroup$ Doesn´t seem to work $\endgroup$ – Jorge Losilla Martínez Jan 31 '16 at 22:29
  • $\begingroup$ Well the idea is to make a script that iterates all selected objects and activates the Disk Cache option. Maybe this should be done via bpy.ops, but I can´t find the path on the python apy $\endgroup$ – Jorge Losilla Martínez Feb 1 '16 at 8:30
  • $\begingroup$ It doesn´t work. Take in consideration that in your script your accesing to a property, not to a method. However thanks for your efforts. $\endgroup$ – Jorge Losilla Martínez Feb 1 '16 at 9:22
  • $\begingroup$ Well. It would nice i f you also add the operator for current cache to bake. $\endgroup$ – Jorge Losilla Martínez Feb 4 '16 at 19:50

Direct Access

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_settings
  • modifiers['ClothModifierName'].settings
  • modifiers['ClothModifierName'].point_cache

which also contain all the relevant attributes.

enter image description here Click to enlarge

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'>

Multiple Objects

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

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.