Changing Blender's default value of properties

Hi! I’m looking for a bit of help.
I’m trying to familiarize with the Blender’s code, to contribute to it.
This may sound very noobish, but I’m having hard time to localize where the properties default values are set. For example the “track_axis” value of an object, declared in “rna_object.c”:

prop = RNA_def_property(srna, "track_axis", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "trackflag");
RNA_def_property_enum_items(prop, rna_enum_object_axis_items);
RNA_def_property_ui_text(prop, "Track Axis",
                         "Axis that points in 'forward' direction (applies to InstanceFrame when "
                         "parent 'Follow' is enabled)");
RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_internal_update");

By default it’s set to “+Y”, where is the code responsible for this?
“properties_object.py” seems to display the value, but does not set anything.

Thanks for any help.

1 Like

Defaults come from RNA (look for RNA_def_property_*_default() calls), function that allocates the struct or startup file. https://developer.blender.org/T47618#360897
A bit messy, which explains why things are hard to locate, and worse, why “reset to defaults” sometimes is useless.

2 Likes

Thanks gsrb3d, there’s a bunch of useful informations in the link you posted.
The problem is, some properties seem to have no “RNA_def_property_*_default()” calls.
For example, I was trying to set to False the default “Show Group Colors” (show_group_colors) of the Action and Graph Editors, since showing colors by default can be very tedious when the group colors are too bright, making the text hardly readable:

1

But I can’t find the default assignment, only this in “rna_space.c”:

prop = RNA_def_property(srna, "show_group_colors", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", SACTION_NODRAWGCOLORS);

I’ve found out that switching:
RNA_def_property_boolean_negative_sdna
to
RNA_def_property_boolean_sdna
just inverts the actual value (group colors are enabled when it’s displayed as false), so the solution is elsewhere (hopefully :slight_smile:)

If no *_default() call try adding it (RNA_def_property_boolean_default(prop, true-or-false-here)), next look for the code that creates new things of that kind, as it could be setting the value, or check what the startup.blend file has.

Also you may want to report a bug against that theme, or whatever code that picks those colors (text and icons). Hard to view is bad UI.

If I remember things correctly, the RNA default values only affect the value used for “Reset to Default Value”. So don’t expect it to be usefull for what you want to achieve. It definitely is misleading though.

There is no single place for defaults unfortunately. What Brecht wrote stands correct, however I’d add that the versioning_xxx.c files often set defaults too for compatibility.

Regarding your examples:

  • track_axis: This property represents Object.trackflag, which gets its default set in BKE_object_init.
  • show_group_colors: This represents a single bit in bArmature.flag, which is set in BKE_armature_add.
1 Like

Thanks for your reply @julianeisel and @gsrb3d.
Actually the show_group_colors I was referring to was the one belonging to the action editor (there are three: action editor, graph editor, armature object).
I’ve finally found out that to invert the default value, it has to be changed in 3 places:
In anim_channels_define.c I changed:
showGroupColors = !(saction->flag & SACTION_NODRAWGCOLORS)
to
showGroupColors = (saction->flag & SACTION_NODRAWGCOLORS);

In action_draw.c:
const bool show_group_colors = !(saction->flag & SACTION_NODRAWGCOLORS);
to
const bool show_group_colors = (saction->flag & SACTION_NODRAWGCOLORS);

In rna_space.c
RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", SACTION_NODRAWGCOLORS);
to
RNA_def_property_boolean_sdna(prop, NULL, "flag", SACTION_NODRAWGCOLORS);

This way it seems there is no issues with backward compatibility.
I don’t know if the patch will be approved, but i’m going to try to submit it anyway…