1
$\begingroup$

I have a Lattice object that applied as modifier in multiple objects. I want to change modifier strength for that objects simultaneously, but appears property for every object. enter image description here

    for o in bpy.data.objects:
        for modifier in o.modifiers:   
            if modifier.type == 'LATTICE':
                layout.prop(modifier, "strength", text="Strength")

how to change to show one parameter for all objects?

Menu code:

import bpy

prepend_menus = [    
    bpy.types.VIEW3D_MT_edit_lattice_context_menu,
]

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

    layout.separator()
   
    for o in bpy.data.objects:
        for modifier in o.modifiers:   
            if modifier.type == 'LATTICE':
                layout.prop(modifier, "strength", text="Strength")
            
    layout.separator()

def register():
    for menu in prepend_menus:
        menu.prepend(cont_menu)

def unregister():
    for menu in prepend_menus:
        menu.remove(cont_menu)

if __name__ == "__main__":
    register()
$\endgroup$
0

1 Answer 1

1
$\begingroup$

So, finally, I achieved the desired result. Maybe for someone it will be useful. enter image description here Video example https://i.sstatic.net/JuqUy.jpg

import bpy
from bpy.props import FloatProperty
from bpy.types import PropertyGroup

prepend_menus = [    
    bpy.types.VIEW3D_MT_edit_lattice_context_menu,
]

class MODIFIERSTRENGTH_PG_main(PropertyGroup):
    def update_modifierstrength(self, context):
        for o in bpy.data.objects:
            for modifier in o.modifiers:   
                if modifier.type == 'LATTICE':
                    modifier.strength = self.str_obj
        
    str_obj: bpy.props.FloatProperty(
        description = "Strength",
        name        = "Strength",
        min         = 0.0,
        max         = 1.0,
        step        = 1,
        default     = 1,
        update      = update_modifierstrength
    ) 

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

    layout.separator()
    if (context.active_object is not None) and (context.active_object.type == 'LATTICE'):
        props  = context.scene.MODIFIERSTRENGTH_PG_main
        layout.prop(props, "str_obj")
    
    layout.separator()

def register():
    for menu in prepend_menus:
        menu.prepend(cont_menu)
    bpy.utils.register_class(MODIFIERSTRENGTH_PG_main)
    bpy.types.Scene.MODIFIERSTRENGTH_PG_main = bpy.props.PointerProperty(type = MODIFIERSTRENGTH_PG_main)

def unregister():
    for menu in prepend_menus:
        menu.remove(cont_menu)
    bpy.utils.unregister_class(MODIFIERSTRENGTH_PG_main)

if __name__ == "__main__":
    register()
$\endgroup$
0

You must log in to answer this question.

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