2
$\begingroup$

Where to prop_search for vertex groups?

This doesn't work:

row.prop_search(context.scene, "vertex_group_density", ob, "vertex_groups", text="Density")

context.scene seems to be the wrong place, but which is the right one? In e.g. the particle system dialog source, there's just a "psys" instead of context.scene, but that doesn't give me a further lead.

Man-pages say "Data from which to take property", I'm not exactly sure what is meant by that:

 prop_search(data, property, search_data, search_property, text="", icon='NONE')

 Parameters:    

    data (AnyType, (never None)) – Data from which to take property.
    property (string) – Identifier of property in data.
    search_data (AnyType, (never None)) – Data from which to take collection to search in.
    search_property (string) – Identifier of search collection property.
    text (string, (optional)) – Override automatic text of the item.
    icon
$\endgroup$
0

1 Answer 1

3
$\begingroup$

here a simple answer using one of the TextEditor -> Python templates:

import bpy


class LayoutDemoPanel(bpy.types.Panel):
    """Creates a Panel in the scene context of the properties editor"""
    bl_label = "Layout Demo2"
    bl_idname = "SCENE_PT_layout"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "scene"

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

        scn = context.scene
        row = layout.row()
        row.prop_search(scn, "vgr", context.active_object, "vertex_groups", text="Density")

def register():
    bpy.utils.register_class(LayoutDemoPanel)
    bpy.types.Scene.vgr = bpy.props.StringProperty(name="vertex_group_density")


def unregister():
    bpy.utils.unregister_class(LayoutDemoPanel)
    del bpy.types.Scene.vgr


if __name__ == "__main__":
    register()

enter image description here

Here we use

  • bpy.types.Scene.vgr to register a StringProperty to keep the string name of the prop_search choice.
  • Accessing the 'vertex_group' happens by passing an object reference, this can be done by using context.active_object or ob if you alias it earlier in the code.. you could have something like:

    ob = bpy.data.objects[some_object_name]
    row.prop_search(scn, "vgr", ob, "vertex_groups", text="Density")
    
$\endgroup$
1
  • $\begingroup$ I think it might help if you could add some explanation as to where they were going wrong in their attempt. $\endgroup$ Jun 24, 2015 at 10:06

You must log in to answer this question.

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