3
$\begingroup$

Re an interesting question in another Q&A : https://blender.stackexchange.com/a/315212/86891

bpy.types.Text, which inherits bpy.types.ID, supports custom properties. It is possible to access, read, and edit them using the API but it would be more convenient to do it directly using the interface.

How can I do that ?

$\endgroup$

1 Answer 1

3
$\begingroup$

There is in fact a builtin helper function to display custom properties in the UI. It is not really documented but available over on the github mirror. We'll use that and display it in the "N" panel of the Text Editor.

enter image description here

from rna_prop_ui import PropertyPanel
import bpy

class TEXT_PT_custom_properties(bpy.types.Panel, PropertyPanel):
    _context_path = "edit_text"
    _property_type = bpy.types.Text
    bl_label = "Custom Properties"
    bl_space_type = "TEXT_EDITOR"
    bl_region_type = "UI"
    bl_label = "Custom Properties"
    bl_category = "Custom Properties"
    
bpy.utils.register_class(TEXT_PT_custom_properties)

FWIW here's the full PropertyPanel file. You don't need to rewrite it, it is builtin and should be available from within the Blender text editor.

https://github.com/blender/blender/blob/main/scripts/modules/rna_prop_ui.py

$\endgroup$
4
  • $\begingroup$ great! +1 the question is: why didn't they add this to default Vanilla Blender? $\endgroup$
    – Chris
    Commented Mar 22 at 8:35
  • 1
    $\begingroup$ @Chris I think there are 2 reasons, the first one, look at the collection custom properties, which was added a few versions ago : simply that noone thought about it, and users didn't complain about it either, and 2, adding a custom property on a text is a bit more abstract than adding a custom property to an object IMO, so it might be a little overwhelming for newcomers. But I think the 1st explanation is the most likely :p $\endgroup$
    – Gorgious
    Commented Mar 22 at 8:47
  • 1
    $\begingroup$ Also, for example asset meta data support custom properties, but there really isn't a point in messing with custom properties in assets since you can't read them from another file without having to open the library file which defeats the purpose of asset meta data. $\endgroup$
    – Gorgious
    Commented Mar 22 at 8:49
  • 1
    $\begingroup$ I think the text editor is a bit forgotten in general. For example anywhere where there is text it is quite common to have a feature where you double click on a word and drag to select whole words, or triple click to select the whole line, but Blender's text editor doesn't have such features. Not a big deal, but it just seems if those are forgotten, it's not surprising. $\endgroup$ Commented Mar 22 at 8:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .