Take the 2-minute tour ×
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It's 100% free, no registration required.

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"
share|improve this question

1 Answer 1

up vote 6 down vote accepted

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

share|improve this answer
    
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... –  Caligari Jul 16 at 9:44
    
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. –  Caligari Jul 16 at 9:50
    
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 –  pink vertex Jul 16 at 22:18
1  
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. –  Pisurquatre Jul 17 at 12:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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