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

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])


briggs (Geoffrey Bantle) 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.
briggs (Geoffrey Bantle) 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.
campbellbarton (Campbell Barton) 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])


bm.free() # free and prevent further access
setting as todo
campbellbarton (Campbell Barton) closed this task as "Resolved".Via Old WorldFeb 19 2013, 6:12 PM

Add Comment