Blender Python: Default Property Type

by Robert   Last Updated September 11, 2019 17:15 PM - source

Short version: Is there a way to specify the default property type of enum flags or bit-flags in the propertyGroup.get() function?

Long version:

When a property of a property group is first accessed without being initialized, such as value = self.Variable or value = self["Variable"], the environment complains that it doesn't exist. So I've been using self.get( "Variable", 0 ) when I'm not sure if the property has been set yet, and this seems to be working.

However, in my current situation, I am trying to retrieve a custom enum flag property and test it against another one with operator &, and the environment keeps complaining about the uninitialized property being an int (because I'm sending 0 as the default). Personally, I don't understand why it won't accept int as an input, but I'm trying to convert the default value into a flags type.

I believe I can use certain operators inside of get to instruct it to provide a specific type, such as self.get("x",[]) for lists, or self.get("x",()) for tuples, or self.get("x",{}) for dictionaries. If this is true, how would I instruct the function to give me an enum flag variable? Is this possible?

And is this even the correct way to deal with properties? Maybe I am going about it the wrong way? Perhaps there is some way to access them to avoid the need for get() altogether?



Related Questions


Its ok in using bpy.app.handlers for an addon?

Updated March 29, 2018 14:15 PM

Create a Button with a Large Icon

Updated April 03, 2018 15:15 PM

Blender Python: Output Paragraph of Text?

Updated September 09, 2019 13:15 PM

Blender Python: Access Selected Collections?

Updated September 11, 2019 02:15 AM

Blender Python: Property Description String Limit?

Updated September 11, 2019 15:15 PM