Hello All,
I received a PM request for creating a custom Enum property. I thought I’d just post it, for all types, here for everyone to see.
To use this script paste it into a text window and run it.
Then Select an object and activate the object context.
Scroll to the bottom of the panel to view the various types in the panel.
import bpy
from bpy.props import IntProperty, FloatProperty, StringProperty, BoolProperty, EnumProperty
def updateIntParameter(self,context):
# This def gets called when one of the properties changes state.
print(self.my_int)
def updateFloatParameter(self,context):
# This def gets called when one of the properties changes state.
print(self.my_float)
def updateBoolParameter(self,context):
# This def gets called when one of the properties changes state.
print(self.my_bool)
def updateStringParameter(self,context):
# This def gets called when one of the properties changes state.
print(self.my_string)
def updateEnumParameter(self,context):
# This def gets called when one of the properties changes state.
print(self.my_axis)
class cls_IntFloatString(bpy.types.PropertyGroup):
# The properties for this class which is referenced as an 'entry' below.
my_bool = bpy.props.BoolProperty(name="My Boolean", description="Boolean.", update=updateBoolParameter)
my_int = bpy.props.IntProperty(name="My Integer", description="Integer.", default=1, min=0, max=12, update=updateIntParameter)
my_float = bpy.props.FloatProperty(name="My Float", description="Float.", default=1.0, min=0.000, max=18.0, step=3, precision=4, options={'ANIMATABLE'}, subtype='FACTOR', unit='NONE', update=updateFloatParameter)
my_string = bpy.props.StringProperty(name="My String", description="Type your string here.", update=updateStringParameter)
axis_types = [
("0","None","None"),
("1","X","X"),
("2","Y","Y"),
("3","Z","Z"),
("4","XY","XY"),
("5","YZ","YZ"),
("6","XZ","XZ"),
("7","XYZ","XYZ"),
("8","ZXY","ZXY"),
("9","XZY","XZY"),
]
my_axis= EnumProperty(name="My Axis", description="The axis that will be relayed to the target.", default="7", items=axis_types, update=updateEnumParameter)
bpy.utils.register_class(cls_IntFloatString)
# Add these properties to every object in the entire Blender system (muha-haa!!)
bpy.types.Object.My_List_Index = bpy.props.IntProperty(min= 0,default= 0)
bpy.types.Object.My_List = bpy.props.CollectionProperty(type=cls_IntFloatString)
class IntFloatStringPanel(bpy.types.Panel):
bl_label = "Int Float String"
bl_idname = "OBJECT_PT_hello"
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_context = "object"
def draw(self, context):
layout = self.layout
obj = context.object
l = len(obj.My_List)
if l > 0:
entry = obj.My_List[obj.My_List_Index]
box1 = layout.box()
row1 = box1.row()
row1.label(" Label:", icon='INFO')
# Display properties for each type.
box1.prop(entry, "my_string", icon='OBJECT_DATAMODE')
box1.prop(entry, "my_int")
box1.prop(entry, "my_bool")
box1.prop(entry, "my_float")
box1.prop(entry, 'my_axis')
else:
# This list is zero length, so let's add one.
collection = obj.My_List
collection.add()
def register():
bpy.utils.register_class(IntFloatStringPanel)
def unregister():
bpy.utils.unregister_class(IntFloatStringPanel)
if __name__ == "__main__":
register()