Read only property
I passed in only a get()
function to the parameter constructor to make
a read-only result, but now I can’t set the values via code.
Confused as to why you think cannot just set the value of a read only property in the get method.
Silly example, in the main thread sets the value of _booble_gooble
to (1, 2, 3) This value is used by the float property getter.
This way you have a truly read only property, not one that is being masked in the UI, but possibly available to alter in the custom properties.
import bpy
from bpy.props import FloatVectorProperty
from random import random
_booble_gooble = (random(), random(), random())
class HelloWorldPanel(bpy.types.Panel):
"""Creates a Panel in the Object properties window"""
bl_label = "Hello World Panel"
bl_idname = "OBJECT_PT_hello"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "object"
def draw(self, context):
layout = self.layout
scene = context.scene
col = layout.column()
col.prop(scene, "read_only_float")
def random_value(self):
# self is scene
return _booble_gooble
def register():
bpy.types.Scene.read_only_float = FloatVectorProperty(get=random_value)
bpy.utils.register_class(HelloWorldPanel)
def unregister():
bpy.utils.unregister_class(HelloWorldPanel)
if __name__ == "__main__":
_booble_gooble = (1, 2, 3) # set it
register()