[Bf-committers] Custom Properties - python issues

Tom Edwards contact at steamreview.org
Sat Jan 1 11:22:35 CET 2011


I'm with you on then name length limitation, that's annoying. Otherwise, 
here is how to create and display a proper custom value:

> type.Scene.my_prop = BoolProperty(name="A boolean 
> property",description="Blah",default=False)
> # ...
> layout.prop(scene,"my_prop",text="A UI property element")

There is also StringProperty, IntProperty, EnumProperty and many more; 
check bpy.props. You can probably use CollectionProperty to store a dict 
(or at least a list) but I've never tried.

I didn't try reading your code sample because your line breaks have 
disappeared.

On 01/01/2011 9:41, Hart's Antler wrote:
> 1. KeyError: 'the length of IDProperty names is limited to 31 characters'object['x'*32] = 'why not make the limit 32 or 64?, 31 is an odd number - not possible to use md5sum hashes either as a workaround'
> 2. inner single quotes are invalid## this failslayout.prop( object, "['my-custom-prop']" )		# a better warning should be printed, or single quotes should be supported## this works - double quotes must be usedlayout.prop( object, '["my-custom-prop"]' )
> 3. dicts are allowed, but layout.prop(...) can not show each subkey on its own## (the dict can be viewed as a string from Custom Properties Panel, but thats not very useful for the user) ##object['x'] = {'a':1, 'b':2}box.prop( object, '["x"]["a"]' )		# error: rna_uiItemR: property not found: Object.["x"]["a"]box.prop( object, '["x"]' )		# this also fails
>
> 4. booleans not supported by custom propertiesobject['my-custom-prop'] = True		# converted to 1 without any warninglayout.prop( object, '["my-custom-prop"]', toggle=True )	# toggle is ignored, numeric entry is displayed instead
> ## workaround ##class mypanel(bpy.types.Panel):	bl_space_type = 'PROPERTIES'	bl_region_type = 'WINDOW'	bl_context = "object"	bl_label = "toggle custom prop example"	@classmethod	def poll(cls, context): return True	def draw(self, context):		layout = self.layout		ob = context.active_object		tag = 'my-custom-prop'		if tag not in ob.keys(): ob[tag] = True		v = ob[tag]		if v: icon = 'CHECKBOX_HLT'		else: icon = 'CHECKBOX_DEHLT'		op = layout.operator( 'toggle_prop', text=tag, icon=icon )		op.propname = tag
> class toggle_prop_op(bpy.types.Operator):                	'''operator: prop toggle helper'''  	bl_idname = "toggle_prop"  	bl_label = "toggle"                    	bl_options = {'REGISTER', 'UNDO'}	propname = StringProperty(name="property name", description="...", maxlen=32, default="")	@classmethod	def poll(cls, context): return True	def invoke(self, context, event):		ob = context.active_object		ob[ self.propname ] = not ob[ self.propname ]		return {'FINISHED'}
>
>
> _______________________________________________
> Bf-committers mailing list
> Bf-committers at blender.org
> http://lists.blender.org/mailman/listinfo/bf-committers
>


More information about the Bf-committers mailing list