0
$\begingroup$

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.

$\endgroup$
5
  • $\begingroup$ You have to define all properties similar to alembic_export into your PropertyGroup $\endgroup$
    – Karan
    Oct 8, 2022 at 13:12
  • $\begingroup$ 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. $\endgroup$ Oct 8, 2022 at 15:00
  • $\begingroup$ You should hardcode the property which you need and leave the rest $\endgroup$
    – Karan
    Oct 8, 2022 at 15:46
  • $\begingroup$ 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 blender.stackexchange.com/q/56741/86891 $\endgroup$
    – Gorgious
    Oct 8, 2022 at 17:09
  • $\begingroup$ 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. $\endgroup$ Oct 8, 2022 at 19:16

1 Answer 1

0
$\begingroup$

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()}
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .