1
$\begingroup$

I am still gnawing stubbornly on the concept "dump active object to python script," and gathering snippets that I think can be glued together into the tool I want. But one piece of the puzzle still eludes me. I would like to find out, for any property of an object, what its default value is. I think if I were more familiar with Blender and/or Python this might be a no-brainer, but despite googling around a bit I still haven't found the clue. If someone can throw a small snippet my way that shows how to discover the default value of some property such as, say, Diffuse Intensity, I think I can generalise to other cases.

$\endgroup$
5
$\begingroup$

To get all the default values of all properties defined on the context object. Using the RNA (bl_rna) will apply to all objects in blender.

import bpy

context = bpy.context
obj = context.object

for prop in obj.bl_rna.properties:
    if hasattr(prop, "default"):
        default = prop.default
        print("%s (%s) default:" % (prop.identifier, prop.name), prop.default)
        # check arrays
        if getattr(prop, "is_array", False):
            default_array = [p for p in prop.default_array]
            print("default array", default_array)
            current_value = [p for p in getattr(obj, prop.identifier)]
            print("current value", current_value)
            print("is default value", current_value == default_array)

Also have a look at 2.78/scripts/modules/rna_xml.py which creates xml from blender objects.

$\endgroup$

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.