how to assign property value for many objects one time?

We can asign the build-in property value for many objects one time by pressing alt key.but this operation doesn’t works in the custom property value of addon.
how can I achieve this purpose? does it has any api that I don’t kown to do this?

sorry I post to the wrong thread by mistake ,I should post to python surport thread.

You could loop through the objects and set each property.


for every_object in some_group_of_objects:
    every_object.some_property = some_value

For example if you wish to enable wireframe display for all objects in the scene you would do:


import bpy
for every_object in bpy.context.scene.objects:
    every_object.show_wire = True

or let’s say you wish to add 10 degrees rotation in x axis for every selected object if it’s name starts with ‘C’:


import bpy
for every_object in bpy.context.selected_objects:
    if every_object.name[:1] == 'C':
        every_object.rotation_euler.x += 10

If property names match, you can set custom properties for multiple objects with alt using the interface as well. I did not know that, but just tried it and it seems to work.

I kown how to do this with script code,but I mean I can’t make the custom properties behave like the build-in properties by pressing ALT ,
for example I make an addon there is a custom properties seted to the object type. I want to change this custom properties value of all selected objets at one time by pressing ALT key.
but thanks it seams has no way to do that, now I think out a way to do the similar thing that don’t need to press ALT key, it is define a update function in the FloatProperty type like this:


global oG=none
def Update_func(self, context):
    global oG
    if(oG==none):#only the active object  value as the template and assign to the other selected objects
        oG=context.active_object
        for o in context.selected_objects:
            if(o==oG):
                continue
            o.prop=oG.prop;
        oG=none

bpy.types.Object.prop =FloatProperty(name='t',description='',update=Update_func);


Imdjs,
looks like at least on 3d view, “UI” region - right panel (n) - alt trick does work with custom properties out of the box.

It does seem to work as any other values from any parts of the interface.


import bpy

class SomePanel(bpy.types.Panel):
    bl_label = "SomePanel"
    bl_idname = "somepanel"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"
    bpy.types.Object.SomeProperty = bpy.props.IntProperty(name="Some Property", default=1234)
    @classmethod
    def poll(cls, context):
        return True
    def draw(self, context):
        layout = self.layout
        object = context.object
        row = layout.row()
        row.prop(object, "SomeProperty" , text = "Some Property")
def register():
    bpy.utils.register_class(SomePanel) 
def unregister():
    bpy.utils.unregister_class(SomePanel)

if __name__ == "__main__":
    register()

When the value is increased or decreased with alt pressed down it increases or decreases for every object and if a value is entered and alt+enter is pressed the values for all selected objects are changed by the same amount it changed in the active object. Rightclicking on the value and choosing copy to selected also works.

yes I test again It works when the property is seted to the object type, but it doesn’t works for posebone type using PropertyGroup.
here is my test py file
posebone_test.zip (1.21 KB)


bl_info = {
    "name": "posebone_test",
    "author": "",
    "version": (0, 0, 1),
    "blender": (2,79, 0),
    "description": " ",
    "warning": "--",
    "category": "Animation"}
    
import bpy
from bpy.props import *

class  TEST___Panel(bpy.types.Panel):
    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOLS"
    bl_label = "posebone_test"
    bl_category=" TEST "    
    
    def draw(self, context):
        self.layout.prop(context.active_pose_bone.testPP,'testF',text='test')
    
class PROPERTYGROUP(bpy.types.PropertyGroup):
    testF =FloatProperty(name='test',description='',default=0.25,min=0.0,max=1.0,step=3)

def register():
    bpy.utils.register_module(__name__)
    bpy.types.PoseBone.testPP =PointerProperty(type=PROPERTYGROUP)

def unregister():
    bpy.utils.unregister_module(__name__)
    del bpy.types.PoseBone.testPP
    
if (__name__ == "__main__"):
      register();

try with bl_region_type = “UI” (N panel)

I have try bl_region_type = “UI” it resault the same as bl_region_type = “TOOLS”
but I find out that the problem is using PropertyGroup,if I use bpy.types.PoseBone.testFF=FloatProperty directly it works with the ALT key.


bl_info = {
    "name": "posebone_test",
    "author": "",
    "version": (0, 0, 1),
    "blender": (2,79, 0),
    "description": " ",
    "warning": "--",
    "category": "Animation"}
    
import bpy
from bpy.props import *

class  TEST___Panel(bpy.types.Panel):
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
    bl_label = "posebone_test"
    bl_category=" TEST "    
    
    def draw(self, context):
        if(context.active_pose_bone):
            self.layout.prop(context.active_pose_bone.testPP,'testF',text='test_PropertyGroup')
            self.layout.prop(context.active_pose_bone,'testFF',text='test_floatp')
class PROPERTYGROUP(bpy.types.PropertyGroup):
    testF =FloatProperty(name='test',description='',default=0.25,min=0.0,max=1.0,step=3)

def register():
    bpy.utils.register_module(__name__)
    bpy.types.PoseBone.testPP =PointerProperty(type=PROPERTYGROUP)#can not use ALT key   Χ
    bpy.types.PoseBone.testFF=FloatProperty(name='test2',description='',default=0.25,min=0.0,max=1.0,step=3)#can ALT key  √

def unregister():
    bpy.utils.unregister_module(__name__)
    del bpy.types.PoseBone.testPP
    del bpy.types.PoseBone.testFF

if (__name__ == "__main__"):
      register();


As an alternative to PointerProperty you may use a CollectionProperty with a single item in it.
testPP.add()
and then retrieve data using testPP[0]
CollectionProperty does support alt

@stephen_leger
ok thanks