Friday, January 9, 2015

User Selecting Objects

So you may be wondering how to give a list of objects for a user to select from in your script. One of the ways of doing this is, if you have added a property to bpy.types.Object you can use layout.prop_search(data, property, search_data, search_property). The four arguments are the data in which the property is, the property to be searched for (also takes the name of the selected choice), the data to search in, and the property in the search_data to look for.

For example:

  1. bpy.types.Object.obj = StringProperty(name = "", default = "")
  2. ###inside of panel/operator###
  3. self.layout.prop_search(context.object, "obj", context.scene, "objects")


So this looks at the active object's property "obj" and then looks in context.scene.objects for that property. Once the user selects an object you can find its name by looking at "obj".




No comments:

Post a Comment