1
$\begingroup$

I have been trying to make an Addon that uses Object Properties and have come up with the following code.

import bpy
bpy.types.Object.save_name2 = bpy.props.StringProperty(options={'HIDDEN'}, name='Save Name')

first_object = bpy.context.selected_objects[0]
first_object.save_name2 = "Bob"

I want to hide the property from Blender's ui so people can't change the values, however, the options=hidden does not seem to work.

enter image description here

Does anyone know how to hide the property? I have been looking around from awhile but i can't seem to find anything.

$\endgroup$
3
$\begingroup$

Try using a property group class where you can store all your properties.

import bpy

class MaterialSettings(bpy.types.PropertyGroup):
    my_int = bpy.props.IntProperty()
    my_float = bpy.props.FloatProperty()
    my_string = bpy.props.StringProperty()

bpy.utils.register_class(MaterialSettings)

Assigning these values to the Object like this:

bpy.types.Object.my_settings = bpy.props.PointerProperty(type=MaterialSettings)

Note: you can choose a custom name instead of 'my_settings'

And the name after the 'type=' is the classname of your property group .

You can access these properties like this: object.my_settings.my_float = 3.0 object.my_settings.my_string = "Foo"

This way, only the propertyclass will be visible in the properties tab and is only editable via script!

$\endgroup$
  • $\begingroup$ I think i understand. Would it be possible to get some example code for storing a property group on an object? I can't seem to figure out what (material.my_settings) is because it is not the name of the class or exists in it. Sorry for my lack of understanding as i am still trying to learn python. $\endgroup$ – Ryan Grzesiak Aug 1 '16 at 3:19
  • $\begingroup$ Yes sure, let me update my post! $\endgroup$ – Bert VdB Aug 1 '16 at 4:00
  • 1
    $\begingroup$ Man, you are awesome! It makes it read-only and combines all the properties in one property. Thanks for helping. $\endgroup$ – Ryan Grzesiak Aug 1 '16 at 4:22

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.