Is there such a thing as a generic custom data layer in Blender that holds Strings, Booleans, and Enums? I'm trying to create a text box in edit mode that holds a user input note on a given mesh. Unfortunately, it seems that the note doesn't stay with the given mesh. When another mesh is in edit mode, the same note from the previous mesh is there. Is there another way to do this other than a custom layer? Is this because the text is registered?
import bpy
from bpy.props import *
import bmesh
# ---
# String Properties
# ---
def initSceneProperties():
bpy.types.Scene.StringType1 = StringProperty(
name = "String1")
# ---
# Layout
# ---
class LayoutPanel(bpy.types.Panel):
bl_label = "Test Text"
bl_space_type = "VIEW_3D"
bl_region_type = "TOOLS"
bl_context = "mesh_edit"
def draw(self, context):
scn = bpy.context.scene
layout = self.layout
row = layout.row(align=True)
col = row.column()
col.prop(scn, 'StringType1', text="")
# ---
# Registers
# ---
def register():
bpy.utils.register_module(__name__)
initSceneProperties()
def unregister():
bpy.utils.unregister_module(__name__)
if __name__ == "__main__":
register()
D. Skarn, I came up with something like this as far as to how it should operate. If you start Blender fresh, run the script and add a cube (named "Cube"), then add text to the text box, it will hold that data. If you create a second item (Cube), put it into edit mode, the text box will be blank and text can be entered. You can switch between both items and each object will hold it's text data. I just don't know how to make it so that it is more elegant and doesn't require actually naming the object explicitly. So I guess somehow detecting a new object and instancing the property data? Will property groups do that?
import bpy
from bpy.props import *
# ---
# String Properties
# ---
def initSceneProperties():
bpy.types.Scene.naming = StringProperty(name = "String1")
bpy.types.Scene.naming1 = StringProperty(name = "String1")
# ---
# Layout
# ---
class LayoutPanel(bpy.types.Panel):
bl_label = "Test Text"
bl_space_type = "VIEW_3D"
bl_region_type = "TOOLS"
bl_context = "mesh_edit"
def draw(self, context):
scn = bpy.context.scene
layout = self.layout
obj = bpy.context.edit_object
objectOut = obj.name
row = layout.row(align=True)
col = row.column()
if (objectOut == "Cube"):
col.prop(scn, 'naming', text="")
print(scn.naming)
else:
col.prop(scn, 'naming1', text="")
print(scn.naming1)
# ---
# Registers
# ---
def register():
bpy.utils.register_module(__name__)
initSceneProperties()
def unregister():
bpy.utils.unregister_module(__name__)
if __name__ == "__main__":
register()
context.active_object
to get the text to display. $\endgroup$