Mesh properties API does not allow for zeros in byte array #32581

Closed
opened 2012-09-19 06:37:41 +02:00 by Geoffrey Bantle · 6 comments

%%%easy to reproduce at console with default scene:

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

result:

b'\x01\x02'%%%

%%%easy to reproduce at console with default scene: layer = bpy.data.meshes["Cube"].polygon_layers_string.new("Data") layer.data- [x].value = bytes([1, 2, 0, 1, 2]) print(layer.data- [x].value) result: b'\x01\x02'%%%
Author
Member

Changed status to: 'Open'

Changed status to: 'Open'

%%%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.%%%

%%%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.%%%
Author
Member

%%%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.%%%

%%%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.%%%

%%%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
%%%

%%%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%%%

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

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#32581
No description provided.