Blender has Property functions to provide a UI so that users can specify values, and among them, there is EnumProperty ** that creates a ** select box. There was no problem with this function and setting the selection statically, but I was a little confused when ** setting the selection dynamically **, so for those who have hit the same problem I would like to introduce it to.
The sample code for statically setting the selection is shown below for comparison with the dynamic setting. ** A select box is created by specifying the list created in advance in items **.
static_append.py
import bpy
from by.props import *
#Items you want to display in the select box
axis = (
("X", "X-axis", ""), # (identifier,UI display name,Explanatory text)
("Y", "Y-axis", ""),
("Z", "Z-axis", ""))
transform_axis = EnumProperty(
name = "Transform Axis", #name
description = "Transform Axis", #Explanatory text
items = axis) #Item list to be displayed in the select box
Next, the sample code that dynamically sets the selection items is shown below. Here, ** item specifies a function to create an item list **.
Items to be set are set in the function that creates the item list, and the created item list is returned as the return value of the function. ** The function specified in items is called every time the variable object_list is referenced **, so the selection items can be set dynamically.
dynamic_append.py
import bpy
from bpy.props import *
#Function to create the item list you want to display in the select box
def get_object_list_callback(scene, context):
items = []
#Processing to add items to items...
return items
object_list = EnumProperty(
name = "Object List", #name
description = "Object List", #Explanatory text
items = get_object_list_callback) #Function to create an item list
Recommended Posts