Set attribute of *Property dynamicly?

Hi there.

Is something line this possible?

prop = StringProperty()
prop.name = "abc"
prop.default = "test"

This gives me errors and says, it is not possible.

Is there another way of doing it than this

prop = StringProperty(name="abc",default="test")

Would be neat, to do it dynamicly…

What errors does it give?

It’s not surprising… You can only add properties to types that inherit from bpy.types.ID. Properties don’t work as an unparented variable.

I found a Solution :slight_smile:

args = {
                "name":current.get("name", "no label")
               #add args like default, subtype etc. dynamicly
                }
prop = FloatProperty(**args)

Hey, I’m curious of the context in which you’re using this, would you mind adding a bit of information about howand why you use this method to create properties ? You are creating them at runtime ?

1 Like

Sure.

It might be a missunderstanding. I register the props only in the register() function. However, the addon modifies scene properties, based on my custom props stored in a group/+collection.

And I want several things:

  1. Easily add other props, in one place and not in several different positions in the code.
  2. Add extra functionality (for later)
  3. Populate a Dropdownlist with all my props, but only that, that haven’t been used yet.

So instead of defining a group property with all my props, I create a Dict and write all the stuff I need there.

  1. Prop Type, Name, Default … all the prop related stuff
  2. All Extra functionality (That is needed in my addon)

Than I read the dict in regiter() and register all the props to the group property
but the dict is still accesible in runtime, so I can populate my dropdown with it and also I can execute my addons mainfunction (modify scene properties) based on the Dict (Here the extra functionalities come into play)

I Hope this explanation is understandable :wink:

Can you please share some example on how it would work?

1 Like

I will somewhen in the next days… promise