I'm creating a custom property for each object in my scene but don't want the user to be able to edit it. Is it possible to block the property in ui ? Here is my code :

import bpy

allObjects = list(bpy.data.objects)

for element in allObjects:
    element["myProp"] = "My value"

You might create a custom property and pass only a get method:

import bpy

#default getter
def get_my_prop(self):
    return self['my_prop']

#omit the setter with a given getter to make it read-only
bpy.types.Object.my_prop = bpy.props.StringProperty(get=get_my_prop)

for obj in bpy.context.selected_objects:
    #assign the value directly
    obj['my_prop'] = "My Value"

It looks like this in the properties panel in blender 2.71: getter

  • $\begingroup$ That works very well but when I close and open the blend file, the custom property is editable again. I tried to use the options={'HIDDEN'} in my stringProperty but it doesn't hide my property... $\endgroup$ – Caligari Jul 16 '14 at 9:44
  • $\begingroup$ How can I keep the property not editable by the user from a session to another? I don't need to have it visible in the interface. $\endgroup$ – Caligari Jul 16 '14 at 9:50
  • 1
    $\begingroup$ You can either check the Register option in the text editor to run the script when the blend file is loaded or create an addon. #1 #2 $\endgroup$ – pink vertex Jul 16 '14 at 22:18
  • 2
    $\begingroup$ In order to run the script upon scene loading, you could add your function in a permanent handler, with an @persistent decorator, as seen here: blender.org/documentation/blender_python_api_2_60_6/… This way, when you load a scene, the script runs automatically. $\endgroup$ – Pisurquatre Jul 17 '14 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.