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$
  • 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$ – pink vertex Feb 18 '14 at 17:14
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$

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.