Mesh properties API does not allow for zeros in byte array
Closed, ResolvedPublic

Description

easy to reproduce at console with default scene:

layer = bpy.data.meshes["Cube"].polygon_layers_string.new("Data")
layer.data[0].value = bytes([1, 2, 0, 1, 2])
print(layer.data[0].value)

result:

b'\x01\x02'

Geoffrey Bantle (briggs) set Type to Bug.Via Old WorldSep 19 2012, 6:37 AM

Confirmed, to support we need to
- add a length variable to the MStringProperty struct. so it can have a length besides 256
- add a callback into rna that can set byte strings - current assignment only takes a 'const char *' which is assumed to be NULL terminated.
... a new callback would have to take a length argument too.

For BMesh support this is simple but for rna a few callbacks would have to support this especially.

Geoffrey Bantle (briggs) added a comment.Via Old WorldSep 20 2012, 7:42 PM

Additionally the name of the property layer is misleading, you cannot actually assign strings at all, it must be a bytes object (which makes it especially broken at the moment). I understand this is probably for historical reasons but thought I should mention it anyway.

Campbell Barton (campbellbarton) added a comment.Via Old WorldJan 9 2013, 2:27 PM

Committed support for bmesh: r53681.
# ---
import bpy
import bmesh

me = bpy.context.object.data

bm = bmesh.new() # create an empty BMesh
bm.from_mesh(me) # fill it in from a Mesh

layer = bm.verts.layers.string.new()
v = bm.verts[0]
v[layer] = bytes([1, 2, 0, 1, 2])

print(v[layer])

bm.to_mesh(me)
bm.free() # free and prevent further access

setting as todo
http://wiki.blender.org/index.php/Dev:2.5/Source/Development/Todo/Scripting#Python.2FRNA_API_Design_TODO

Campbell Barton (campbellbarton) closed this task as "Resolved".Via Old WorldFeb 19 2013, 6:12 PM

Add Comment