0
$\begingroup$

I have a script like this:

import bpy

for reference_object in bpy.data.objects:

    for slot in reference_object.material_slots:
        mat = slot.material
        nodes = mat.node_tree.nodes
        for node in nodes:    
           # print(node.name + '\n')
            try:
                attribute_name = node.attribute_name
                if not (attribute_name in reference_object.rna_type.properties.keys()):
                    reference_object[attribute_name] = 0.0
                    id_props = reference_object.id_properties_ui(attribute_name)
                    id_props.update(min=0,max=1,)
                    reference_object.property_overridable_library_set('["attribute_name"]', True)
            except Exception as e:
               # print(e)
               pass
                           
selection_names = bpy.context.selected_objects        
def add_driver(target, source, prop):
    ''' Add driver to source prop (at index), driven by target dataPath '''


    d = target.driver_add(f'["{prop}"]').driver
    if len(d.variables) == 0:
        v = d.variables.new()
    else:
        v = d.variables[0]
    v.name                 = prop
    v.targets[0].id        = source
    v.targets[0].data_path = f'["{prop}"]'

    d.expression = prop
                
objects = bpy.context.selected_objects
controller = bpy.context.active_object

for obj in objects:
    if obj != controller:
        try:
            #print(obj['Opacity'])
            add_driver(obj, controller, 'Opacity')
        except Exception as e:
            #print(e)
            pass

But even after reading this: https://developer.blender.org/docs/release_notes/3.0/python_api/

I still can't figure out how to change the property type to boolean or subtype to factor for example.

$\endgroup$

1 Answer 1

1
$\begingroup$

The type is changed by changing the value when the property is created. For example:

attribute_name = 'your prop'
your_object[attribute_name] = 0.0 # float type
your_object[attribute_name] = 0 # interger type
your_object[attribute_name] = True # boolean type

The subtype is changed by an additional parmeter in the "id_props.update" line.

id_props = your_object.id_properties_ui(attribute_name)
id_props.update(min=0,max=1,subtype="FACTOR")
your_object.property_overridable_library_set(f'["{attribute_name}"]', True)

"Caps Lock" is necessary.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .