Skip to main content
Bumped by Community user
added 1913 characters in body
Source Link
Robert
  • 1.4k
  • 2
  • 14
  • 35

It seems difficult to find any information about enum-flag usage and workflow. I'm familiar with bitflags and related operations, but the blender/python specifics are fun to figure out.

Is there any clever (or possibly obvious in my case) mechanism to convert enum flags into a string? It is primarily for debugging, but user friendly would be a plus.

The way enum properties are defined in Blender makes me wonder if the flags are not already defined as a string in some way.

Edit: For example, my flags are defined like this:

FBXG_Mode=[
            # mode flags
            ('GA', "Asset", "...", 1),
            ('LP', "Low", "...", 2),
            ('HP', "High", "...", 4),
            
            # system flags
            ('EXCLUDE',"","",8),
            ('RENAMED',"","",16),
            ('DELETE',"","",32),
            ]

And it seems we can check for flags using strings like this..

if 'GA' in MyFlags:

By the way, how exactly does this work? Does the environment process this correctly because it associates the MyFlags variable with the FBXG_Mode list?

I'm very new to Python, so I have a couple questions if anyone knows the answers:

  1. What tells the environment the attribute order of my FBXG_Mode list? Eg, how does it know that I placed the flag names into the second column/entry? Is this just hard-coded somewhere in the Blender or Python environment? Where would I find documentation about this? I'm not sure what this is called.

  2. How do I access an element of FBXG_Mode in a way that allows me to access the name, description, value, etc? Would it be FBXG_Mode[0][1]? I'm looking for something more like FBXG_Mode['GA'].Description, or at least FBXG_Mode['GA'][2]. I would like to avoid the hard-coded indices if possible.

  3. Is it possible to access the strings and/or properties of the FBXG_Mode list using only the MyFlagsvariable after it is assigned or associated with it? Does a flags variable have any type of association after it is assigned, or is the association only available during the assignment?

  4. Is there any quick/automatic way to extract the toggled flags of a variable in string form, such as for printing text? This seems like something a generic function could be written to do, so I'm wondering if one already exists? Especially since Blender can generate UI controls basically the same way.

Thanks for any help!

It seems difficult to find any information about enum-flag usage and workflow. I'm familiar with bitflags and related operations, but the blender/python specifics are fun to figure out.

Is there any clever (or possibly obvious in my case) mechanism to convert enum flags into a string? It is primarily for debugging, but user friendly would be a plus.

The way enum properties are defined in Blender makes me wonder if the flags are not already defined as a string in some way.

It seems difficult to find any information about enum-flag usage and workflow. I'm familiar with bitflags and related operations, but the blender/python specifics are fun to figure out.

Is there any clever (or possibly obvious in my case) mechanism to convert enum flags into a string? It is primarily for debugging, but user friendly would be a plus.

The way enum properties are defined in Blender makes me wonder if the flags are not already defined as a string in some way.

Edit: For example, my flags are defined like this:

FBXG_Mode=[
            # mode flags
            ('GA', "Asset", "...", 1),
            ('LP', "Low", "...", 2),
            ('HP', "High", "...", 4),
            
            # system flags
            ('EXCLUDE',"","",8),
            ('RENAMED',"","",16),
            ('DELETE',"","",32),
            ]

And it seems we can check for flags using strings like this..

if 'GA' in MyFlags:

By the way, how exactly does this work? Does the environment process this correctly because it associates the MyFlags variable with the FBXG_Mode list?

I'm very new to Python, so I have a couple questions if anyone knows the answers:

  1. What tells the environment the attribute order of my FBXG_Mode list? Eg, how does it know that I placed the flag names into the second column/entry? Is this just hard-coded somewhere in the Blender or Python environment? Where would I find documentation about this? I'm not sure what this is called.

  2. How do I access an element of FBXG_Mode in a way that allows me to access the name, description, value, etc? Would it be FBXG_Mode[0][1]? I'm looking for something more like FBXG_Mode['GA'].Description, or at least FBXG_Mode['GA'][2]. I would like to avoid the hard-coded indices if possible.

  3. Is it possible to access the strings and/or properties of the FBXG_Mode list using only the MyFlagsvariable after it is assigned or associated with it? Does a flags variable have any type of association after it is assigned, or is the association only available during the assignment?

  4. Is there any quick/automatic way to extract the toggled flags of a variable in string form, such as for printing text? This seems like something a generic function could be written to do, so I'm wondering if one already exists? Especially since Blender can generate UI controls basically the same way.

Thanks for any help!

Source Link
Robert
  • 1.4k
  • 2
  • 14
  • 35

Blender Python: Convert Enum Flags into String?

It seems difficult to find any information about enum-flag usage and workflow. I'm familiar with bitflags and related operations, but the blender/python specifics are fun to figure out.

Is there any clever (or possibly obvious in my case) mechanism to convert enum flags into a string? It is primarily for debugging, but user friendly would be a plus.

The way enum properties are defined in Blender makes me wonder if the flags are not already defined as a string in some way.