Tutorial - Add a bool
- This is short tutorial, how to add a bool property to user_preference.
- I dont know how to setup patches with the build i use.
- I write fake patches and edit the source code directly.
- This is the kind of property you are going to add.
- ファイル:K bool 00
- To do this we need patch three files.
- blender\source\blender\makesdna\DNA_userdef_types.h
- blender\source\blender\makesrna\intern\rna_userdef.c
- blender\release\scripts\startup\bl_ui\space_userpref.py
DNA
- DNA, struct DNA, is where the blender data is defined.
- There are different types, enums, structs (which memory usually allocates), etcetra.
- Open blender\source\blender\makesdna\DNA_userdef_types.h.
- Look for the, eUserpref_UI_Flag, and eUserpref_UI_Flag2 enums.
- The max used in this list is 32.
- Add a new one to the bottom of eUserpref_UI_Flag2. Or 3 if exist.
Index: source/blender/makesdna/DNA_userdef_types.h
===================================================================
- USER_TRACKPAD_NATURAL = (1 << 2)
+ USER_TRACKPAD_NATURAL = (1 << 2),
+ USER_MY_PROPERTY = (1 << 3)
===================================================================
RNA
- RNA is the python interface.
- Before you can use the property in user preferences with python, you need to setup the ; interface.
- Open blender\source\blender\makesrna\intern\rna_userdef.c
- Look for the, rna_def_userdef_view function.
- Scroll down to /* display */.
- Copy the code from a bool type property, then add it to the end of the /* display */ section.
- Modify the names.
- "my_property"
- USER_MY_PROPERTY
- "Property"
- "My Property"
Index: source/blender/makesrna/intern/rna_userdef.c
===================================================================
+ prop = RNA_def_property(srna, "my_property", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", USER_MY_PROPERTY);
+ RNA_def_property_ui_text(prop, "Property", "My Property");
+
===================================================================
Python
- Open blender\release\scripts\startup\bl_ui\space_userpref.py
- Add the property to the display section.
Index: release/scripts/startup/bl_ui/space_userpref.py
===================================================================
+ col.prop(view, "my_property")
===================================================================
- Compile blender.
- If all works, you should see and be able to set "my_property" in User_Preference, Interface.
- You can now use this bool/property for conditional code in C or Python.