3
$\begingroup$

I would like to apply a custom parameter to a selection of objects with the following setup:

class MyPanel(bpy.types.Panel):
    bl_label = "Tool"
    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOLS"


    @classmethod
    def poll(cls, context):
        return len(context.selected_objects) > 0

    def draw(self, context):
        layout = self.layout

        myprop = context.active_object.myprop
        row = layout.row()
        row.prop(myprop, 'subdivs')

For now it works with the active_object, but how do I have to change my panel so it can pass on multiple variables to my update function?

$\endgroup$
1
  • 2
    $\begingroup$ "how do I have to change my panel so it can pass on multiple variables to my update function ?" What is the update function supposed to be. This question is unclear. $\endgroup$ Commented Feb 18, 2014 at 17:14

1 Answer 1

5
$\begingroup$

bpy.props allows you to define your own get/set/update methods for a property.

import bpy

def update(self, context):
    #self ~ owner of the property
    for obj in context.selected_objects:
        #assigning a value to obj.property would cause a recursion!!!
        obj["custom_property"] = self.custom_property

bpy.types.Object.custom_property = bpy.props.IntProperty(update=update)

If you change the attribute custom_property for an object the change will be applied to all selected objects.

You can also use drivers to synchronize properties.

$\endgroup$

You must log in to answer this question.

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