0

I'm writing an addon that needs to have the same properties as another operator (i.e the Alembic exporter properties). But I'm not sure how to register them? Normally I create a PropertyGroup and add my properties in the init.py file.

class MyProperties(bpy.types.PropertyGroup):
    my_bool: BoolProperty(
        name="A bool",
        description="",
        default = False
        )
etc...

But how do I add properties that I have in a list?

def get_alembic_props():
    props = []
for prop in bpy.ops.wm.alembic_export.get_rna_type().properties:
    # In this example, just add bools.      
    if prop.type == "BOOLEAN":
        new_prop = bpy.props.BoolProperty(
            identifier = prop.identifier,
            name=prop.name,
            description=prop.description,
            default=prop.default
        )

return props

class MyProperties(bpy.types.PropertyGroup): abc_props = get_alembic_props(): for prop in abc_prop: ...somehow add the prop...

Also, is it correct to use the operator.get_rna_type().properties to get the properties of another operator? It seems like the all return something called _PropertyDeffered.

Simon Björk
  • 165
  • 1
  • 10
  • You have to define all properties similar to alembic_export into your PropertyGroup – Karan Oct 08 '22 at 13:12
  • Yes, but as I show in the example it's unclear to me how to define a property (dynamically) in a loop. I don't want to hardcode the values. – Simon Björk Oct 08 '22 at 15:00
  • You should hardcode the property which you need and leave the rest – Karan Oct 08 '22 at 15:46
  • I agree that trying to dynamically retrieve another operator's props in another op can be problematic. I would go to the file where the operator is defined in your blender install and just copy/paste the properties. Requiring an operator to be registered in another operator's definition is a recipe for error because of how unpredictable registering is. However if you really want you can dynamically define operators using this method https://blender.stackexchange.com/q/56741/86891 – Gorgious Oct 08 '22 at 17:09
  • It's not great to hard code the properties, as they are updated pretty often, i.e the USD exporter. There's a lot of if/else statements depending on versions and it will always be required to update the addon when something changed in for example the USD exporter. – Simon Björk Oct 08 '22 at 19:16

1 Answers1

0

I found a solution that seems to work here. Not sure if there are any problems in doing it like this?

class AlembicProps(bpy.types.PropertyGroup):
    # Basic example, just supporting BoolsProperty
    __annotations__ = {x.identifier: bpy.props.BoolProperty(name=x.identifier, default=x.default) for i in get_alembic_props()}
Simon Björk
  • 165
  • 1
  • 10