4
$\begingroup$

A problem I often encounter when making a custom operator is that I must create properties that mirror properties already in Blender. If these properties are floats or ints or strings, it's no big deal, but if they are enums, it's a pain (literally, I've got arthritis).

For example, if I want to create a cube and then add a bevel modifier, the bevel modifier has an "offset_type" property, which is an enum.

I can of course create an enum that mirrors the options in the native enum, but is it possible to somehow to access the enum that must already exist somewhere in Blender? I would have an "register/undo" properties panel populated by a draw function.

# in my draw function, # instead of this: layout.prop(self, 'my_offset_enum') # I'd like to do something like: layout.prop(bpy.some_class_in_blender, "blenders_offset_enum") 
$\endgroup$
1
  • 2
    $\begingroup$ Hello, I took the liberty to rename the title of your question to reflect more what I think you were actually looking for. Feel free to rollback if I missed the point. Cheers $\endgroup$ Commented Jun 16, 2022 at 15:10

2 Answers 2

4
$\begingroup$

layout.prop(thing, 'name') changes the value of thing.name, so you can use layout.prop(modifier, 'offset_type') to change the modifier's offset_type directly. For example:

if "Bevel" in obj.modifiers: row.prop(obj.modifiers["Bevel"], "offset_type") 

You can also dynamically access the EnumProperty of a property like this if you want to mirror it in your own property

enum_property = bpy.types.BevelModifier.bl_rna.properties['offset_type'] item = enum_property.enum_items[0] print(item.name, item.value, item.description) 
$\endgroup$
1
  • $\begingroup$ Your answer gave me a jumping-off point to get to what I needed. Thank you. $\endgroup$ Commented Jun 16, 2022 at 14:45
3
$\begingroup$

Thanks to scurest's answer above, which I used as a jumping-off point, and lots of print statements later, what ended up working was putting a property in my operator, like so...

blenders_offset_types = bpy.types.BevelModifier.bl_rna.properties['offset_type'].enum_items my_offset_types : bpy.props.EnumProperty( items = [(ot.identifier, ot.name, ot.description, ot.value) for ot in blenders_offset_types] ) 
$\endgroup$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.